3

I am trying to customize the front end features.

I could easily add the alias field by adding this around line 106 of my override \templates\protostar\html\com_content\form\edit.php:

<?php echo $this->form->renderField('alias'); ?>

But now I am strugguling to add the association tab and field (like in backend) as well as the the category one. I"ve tried this, but without succes:

<?php echo $this->form->renderField('associations'); ?>
<?php echo $this->form->renderField('category'); ?>

My knowledge of php is quite limited and even a carefull analysis of \administrator\templates\isis\html\com_content\article\edit.php didn't help much (I though frontend and backend editing page would be built the same way but apparently no).

Thanks a lot for your help!

2

You are right. Front-end and Back-end models are different. To be precise:

  • In back-end site, ContentModelArticle is a JModelAdmin
  • In front-end site, ContentModelArticle is a JModelItem

For instance, in front-end site, the article view has a very different article.xml form than in the back-end site.

Thus, you can only render those fields. E.g. category should be catid

  • Thanks for this! I could learn a bit more about JModelItem, but I am not yet able to grasp the whole concept. I have replace <?php echo $this->form->renderField('category'); ?> by <?php echo $this->form->renderField('catid'); ?> and indeed the category field appear on the edit page but I can't change the category. Also I couldn't find any info about the JModelItem association field. – MagTun Jul 26 '14 at 8:11
  • 1
    You are trying to reuse JModelItem to add new articles with extended behaviour. Still, by definition JModelItem has limited features for front-end usage. To achieve what you are looking for, you most probably have to implement a new form, model, and everything else, duplicating features from JModelAdmin. From my experience, I can say it's not easy the reuse core models, and at end it's simpler to duplicate the original code to solve the requirement. Moreover, there's no official API on content model and it can change at any time; that is to say, building your own model is safer. – Anibal Jul 26 '14 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.