This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hi there! I am new to plugin/backend development in general. I was wondering about how I might going about pulling in data from a table I have setup using the really nifty builder plugin. Basically, this plugin allows you to create custom "post" types without much backend knowledge and it really is an elegant way to go about it.
I was reading the components docs, but to no avail.
I thought a query like this might work
function onInit()
{
$this['records'] = myModel::get();
}
Basically, what I am trying to do is to be able to key in data from the columns of my table I have setup so I can use it for things like naming of the page, slug, content, featured img etc etc. For example I'd like to be able to pull in {{ title }}, perhaps, into the html so I can add classes where I need and have full control of the html.
Here's the video they used to setup the plugin, which I followed, and was successful in setting up the db and the backend management. Basically, I got all the way until the end of the video, but I am just not understanding how to pull in the data into a page/partial.
Do I even need to use the component necessarily or can I just call the table? Or is there something about registering the component that I am missing?
EDIT: So, I think I figured out how to pull in the data without referencing the component. I loaded the component, but didn't include the partial and just referenced each tag like this:
<section>
<picture class="bg-img">
<img src=/storage/app/media{{ attribute(record, 'featured_img') }} alt="Test" />
</picture>
<div class="main">
<header>
<h1>
{{ attribute(record, 'title') }}
</h1>
</header>
</div>
</section>
This let's me pull in each individual column to display the data. However, they do not work in the page title for some reason and I can't quite figure that out. If anyone has any ideas I'd be greatly appreciative.
EDIT 2: I FIGURED IT OUT. Leaving this here for indexing so others can see on the googles.
To alter meta data I referenced this other October post.
Or if the post got taken down and for the lazy:
<?php
function onEnd()
{
$this->page->title = $this->record->title;
$this->page->meta_description = $this->record->sub_title;
$this->page->meta_title = $this->record->title;
}
This will overwrite your twig markup when placed in your code section. The only thing I don't know, is what are these keywords called in the php...the "page" part and the "title" part? How can I read into more documentation about that?
Keep in mind this is specific to my project using the builder plugin. So, some of the language at the end of the strings will be different for you if you're using another plugin or table etc.
Last updated
1-1 of 1