rainlab/builder-plugin

Display A Single Column Record In the Page Title

Closed this issue · 1 comments

Thank you for the plugin and the nice documentation with the video. It was very insightful into backend development, something I am very bad at, but learning.

I was able to setup my plugin, but I was wondering if I am doing this right.

I used my component, but didn't call the partial. Then I referenced each column of my table in page. (This is for a custom blog-type format I am developing)

This is what I have and it seems to work good, though I am uncertain if this is the better way of doing it:

<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>

What I am wondering, is there a way to key in a record of a column from my table into the page title?

That way when a post get's pulled it uses the title of the post as the page title? And same thing for all the fields under "settings", for example, meta or meta description etc. It seems to be that the markup record tags only work inside the twig markup.

EDIT: I figured this out. I'll leave here for others to view.

What I was able to do was

<?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 programatically overwrites the twig markup. 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?

Hey @codingcrafter, yes that's it. We have some improvements to this approach in the next version (v2.2) where you can simply define the title inside the page configuration. Like this

title = "{{ record.title }}"
meta_description = "{{ record.sub_title }}"
meta_title = "{{ record.title }}"
==
Page contents

However, the way you've done it is also correct. Great job! Thanks for sharing your result.