DEV Community

M. Alexandre J-S William ELISÉ
M. Alexandre J-S William ELISÉ

Posted on • Originally published at alexandre-elise.fr on

1

[astuce] Les champs personnalisés pour les non-developpeur(se)

Ami(e)s Joomlers,

Cette fois ci je vais présenter un code tout simple à copier coller que vous pouvez utiliser directement dans vos surchages de template de com_content (articles) . Pour ceux et celles qui veulent rajouter des champs personnalisés simplement dans leur templates préférées voici les deux bouts de code à mettre. Un en haut et l'autre là où vous souhaitez afficher votre champ personnalisé (requiert Joomla! 3.7.x minimum).

ex: Dans le fichier templates/example/html/com_content/article/defaut.php

<?php

defined ('_JEXEC') or die();

//code specifique à votre template...

// Début: Bout de code à rajouter tout en haut

JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');

$champs_par_nom = \Joomla\Utilities\ArrayHelper::pivot($this->item->jcfields, 'name');

// Fin: Bout de code à rajouter tout en haut

?>

<?php

//...

//code specifique à votre template...

//...

// Début: Bout de code à rajouter

// là où vous voulez afficher

// un champ personnalisé grâce à son nom

echo $champs_par_nom['mon-champ-personnalise']->label

. ':' . $champs_par_nom['mon-champ-personnalise']->value;

// Fin: Bout de code à rajouter

// là où vous voulez afficher

// un champ personnalisé grâce à son nom

?>

Voilà, c'est tout pour aujourd'hui. A bientôt les Joomlers de l'extrême!

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more