I am using a CCK (Seblod) that extends com_content and allows adding complex fields, like PHP code to be run on onBeforeRender event. I need to change the values of some attribs of an article in the article view, specifically set show_title to 0 to hide native Joomla title and replace it with a custom field, and I am trying to to that through this php field attached to before render event.

I have checked that in this before render context, I cannot access the $this object (it gives me the classical error "Using $this when not in object context"), but I can access current article via

$article = JTable::getInstance("content");

where the $id is taken from JInput. I have also seen that I can read the show_title value in the JSON value retrieved with $article->attribs.

But, as a beginner Joomla developer, I cannot find a way to change that value. Just to be clear: I don't want to change it in the DB (for which I have read I should use JTable->store), I need to change it in the before render so that native Joomla title is not displayed.

$article->attribs->set... of course does not work since $article->attribs is just a string... but also maybe JTable is not the correct way to do that because it maps to the db...

Is it possible to do that in this context (no access to $this)?

  • 1
    I got rather confused by your first paragraph, in particular "a third party component (that extends com_content) and is executed as a before render". Joomla components don't really "extend" other components, and a "before render" would be a plugin rather than a component. Could you clarify? And is there a particular reason why can you not do this in a content plugin that triggers on onContentPrepare (docs.joomla.org/Plugin/Events/Content#onContentPrepare) where the article is passed by reference and you can easily change it? That would be the usual way of doing something like this. Sep 19, 2020 at 15:11
  • Hi Robbie, I try to explain: I am using a CCK that extends com_content with additional fields. One of these field is a BeforeRender field where the user can write its PHP to do things before the rendering. I am looking for code to write in this field in order to disable showing Joomla title so that another field is shown as h1. Inside the before render field, $this has no value, I can access JFactory, JDocuments... and didn't find a way so far to change article attribs (that I can access thorugh JTable) to set show_title to 0. Is it more clear now? Thanks
    – Nene
    Sep 19, 2020 at 17:24
  • Thanks @Nene, that's clearer now. But more difficult to solve! If your code is running when the Joomla system onBeforeRender event is raised, then I think the component (com_content) will have already been run, and its output buffered with ob_start. So you could check by accessing ob_get_contents and seeing what it contains. If your element is there then you could maybe replace it and regenerate the output buffer. Sorry, I can't think of any other possibility for tackling this. Sep 19, 2020 at 21:44
  • Welcome to JSE, @rene. Please add all relevant details (even if responding to a comment) to the question as an edit so that the full story is all in one cohesive location on the page. Every time your question is edited, it will be bumped to the top of the Active question queue where it will potentially gain renewed attention from volunteers. As an aside, perhaps introduce yourself and tell us about your Joomla "story" by editing your profile. Sep 19, 2020 at 22:16
  • @RobbieJackson thanks. Parsing and regenerating all the output buffer seems to me a bit heavy for performance, am I correct? Anyway I tried to write var_dump(ob_get_contents()) and I get a sad NULL string(0) " BTW, I never used ob_get_contents so now I am going to search around..
    – Nene
    Sep 21, 2020 at 21:16


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.