How to set a php condition with field value ?

More
2 years 8 months ago #81951 by bendeb
Hello,
I want to set a php condition with the value of a field.

I have a text field (named "level") with numerical values (1 to 9).
I want to set a php condition in my category template to display all items with "level" = 1, then below display all items with "level" = 2, etc.

I know I can display all my items by ordering the listing with the value of "level" field in FC parameters, but I want to add some text between all "level" before displayins items.

So I have to modify my category_items.php of my template and set manually the condition.

In category_items.php, I have this for now :
Code:
<?php foreach ($items as $i => $item) : ?> ___ some html ___  <?php endforeach; ?>
And of course it display all items regardless the "level" field value.
If I order by field value, I obtain this :
- item with "level" set to 1
- item with "level" set to 1
- item with "level" set to 1
- item with "level" set to 1
...
- item with "level" set to 2
- item with "level" set to 2
...
- item with "level" set to 3
- item with "level" set to 3
- item with "level" set to 3
- item with "level" set to 3[/code]


And what I want :
Code:
<h3>Level 1</h3> - item with "level" set to 1 - item with "level" set to 1 - item with "level" set to 1 - item with "level" set to 1 <h3>Level 2</h3> - item with "level" set to 2 - item with "level" set to 2 <h3>Level 3</h3> - item with "level" set to 3 - item with "level" set to 3 - item with "level" set to 3 - item with "level" set to 3

Etc.

What is the correct FC syntax please ?

Thank for your answer.

Regards.

 

Flexicontent 4.1.0b1
Joomla 3.9.18

Please Log in or Create an account to join the conversation.

More
2 years 8 months ago #81952 by micker
for me the best way is more simple
1 create a universal module for each and use advanced scope to filter yourfilterid##yourvalue
2 create a article and load all universal module
that it

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]

Please Log in or Create an account to join the conversation.

More
2 years 8 months ago #81953 by bendeb
Cette méthode ne semble pas convenir à ce que je veux faire.
Dans l'universal module, on peut trier les items par un champ personnalisé, mais on ne peut pas afficher uniquement les items qui ont telle valeur dans ce champ.
Je ne peux donc pas créer un universal module qui m'affiche les items qui ont le champ "level" = 1, un autre avec "level" = 2, etc.

Par ailleurs, même si ça fonctionnait, il me faudrait pour mes besoins créer une quantité astronomique de modules, ce n'est pas du tout pratique.
Alors qu'une simple condition dans le fichier php règlerai ceci facilement.

Il me faudrait un truc dans le genre dans mon fichier php, mais ça ne fonctionne pas :
Code:
<?php       if ($item->fields['level']->display === 1) {       echo 'Niveau 1';       }      elseif ($item->fields['level']->display === 2) {       echo 'Niveau 2';       } ... ... ... ?>

Ou avec un foreach.
Code:
<?php foreach ($items as $i => $item) : ?> *** HTML *** <?php endforeach; ?>
Celui-ci affiche le code html pour tous les items.

Quelle serait la syntaxe pour afficher le html de tous les items qui ont le champ "level" avec comme valeur 1 ? 

Merci d'avance.
 

Flexicontent 4.1.0b1
Joomla 3.9.18

Please Log in or Create an account to join the conversation.

More
2 years 8 months ago #81955 by micker
Hello
En fait dans le module oui tu peus filtrer par champs (pas que l'ordre)
Mais sinon édité ton template depuis l'administration de flexicontent et en dessous de l'éditeur tu as des exemple de chargement de champs

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]

Please Log in or Create an account to join the conversation.

More
2 years 8 months ago #81963 by bendeb
Dans le module, on peut filtrer par champ, mais pas suivant la valeur de ce champ.
On ne peut pas définir uniquement l'affichage de tous les items qui ont comme valeur "1" dans mon champ "level".
Et faire ensuite un autre module qui n'affiche que les items qui ont comme valeur "2" dans le champ "level"

Flexicontent 4.1.0b1
Joomla 3.9.18

Please Log in or Create an account to join the conversation.

More
2 years 8 months ago - 2 years 8 months ago #81964 by micker
Mais si tu peus afficher tous les articles ayant le champ level a la valeur 1 sans aucun soucis relis la partie scope tout en basTu peus même faire des écart entre les valeurs

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]
Last edit: 2 years 8 months ago by micker.

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.394 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline