Générateur de titre, image, contenu dans gestion du contenu

Support en français pour CMS Made Simple.

Moderator: jce76350

Post Reply
kiwii
New Member
New Member
Posts: 7
Joined: Wed Jan 27, 2021 4:12 pm

Générateur de titre, image, contenu dans gestion du contenu

Post by kiwii »

Bonjour/Bonsoir (biffer la mention inutile).

Actuellement en stage en web dev (junior), on m'a demandé de créer un site qui utilise CMS made simple comme cms.
J'ai réussi à créer le gabarit de base, avec des tabs dans mes pages.

Mais je souhaiterais que pour une partie, l'utilisateur (le front user) puisse avoir autant de titre, image, contenu qu'il le souhaite.
Dans l'idée serait un générateur où il suffirait qu'il indique le nombre de "card" qu'il souhaite et le tout s'affiche.

Je vois bien le tabs ainsi :

Fond : select la couleur de fond (variable pour donner la couleur de la card)
Image Gauche (bouton select donnant l'information à une autre variable)
Image Droite (même chose)
Image : téléchargement de l'image
Titre : le titre
Contenu : le contenu

Et après tout ça un bouton +

J'ai installé le module Lise vu que beaucoup de personne sur le forum parle du module seulement, je n'arrive pas à comprendre comment je pourrai générer cette information. Et j'ai suivit les vidéos youtube dont cette vidéo https://www.youtube.com/watch?v=RZowdPt ... OWebDesign malheureusement le module utiliser est obselète.

Bien entendu, je me doute que j'aurai plus simple à modifier le gabarit de gallery ou article pour faire ce que je souhaite faire.
Il m'a fallut deux jours pour comprendre comment modifier le gabarit de navigation pour créer mon sous menu à mon idée. Mais là, ça va faire deux semaines que je cherche comment créer ce que je souhaite.

Pour moi il faudrait créer une variable $j (par exemple) qui serait le nombre de fois que l'utilisateur à besoin d'une carde.
{content block="nombre" tab="Produits" label="Le nombre de card à afficher" assign="j" oneline="true" size="1" wysiwyg='false'}
Créer une boucle qui génère j dans gestion de contenu avec le nombre de card.

Donc la page dois ce recharger.

Et là, je suis totalement perdue.
Je me tourne donc vers vous pour avoir plus d'information.
Il faut savoir que je suis plus Front que Back, je me débrouille en php mais j'ai plus facile étrangement avec smarty php.
Je n'ai pas peur de chercher sur google et le forum. J'ai pratiquement terminée de lire l'ancien forum français de cms made simple.
Et je remercie ceux qui ont passé leur temps à écrire des tutos.
kiwii
New Member
New Member
Posts: 7
Joined: Wed Jan 27, 2021 4:12 pm

Re: Générateur de titre, image, contenu dans gestion du contenu

Post by kiwii »

[strike]C'est encore moi [/strike]

Une autre idée serait de créer des pages qui s'affichent que sur la page parent (mais qui sont dans le menu).
Et le lien dans le menu renverrait donc sur la page parent à l'endroit où est la page enfant.
Un peu comme une ancre qui n'en serait pas une. Et à part me trouver des idées, vous pouvez constater que je suis totalement perdue.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Générateur de titre, image, contenu dans gestion du contenu

Post by velden »

From what I understand (I used Google Translator) you want content blocks (titles, images, text) DYNAMICALLY added to a page template.
This is by default NOT (yet) possible in CMS Made Simple. I know some module developers have ideas to make one, and I've been playing with a module myself too that never has been published.

LISE is indeed a module to create dynamic lists BUT by default those lists are not connected to their own page (this may be possible though) and the lists are not editable from within the page editor itself.

Your idea of creating a page with sub-pages is possible. You could use the Navigator module to get all sub pages of the current page and then use the page_attr tag (https://docs.cmsmadesimple.org/tags/cms ... /page_attr) to retrieve the content from those sub pages.
However, there are some drawbacks like: efficiency, every page MUST have a title, alias, default content etc
kiwii
New Member
New Member
Posts: 7
Joined: Wed Jan 27, 2021 4:12 pm

Re: Générateur de titre, image, contenu dans gestion du contenu

Post by kiwii »

Thank you very much, I also go through a translator to answer you. I'm sorry if it's not understandable.

I had also thought of page_attr except that I don't understand the principle. And on the other hand, I would like the end user to be able to add as many child pages as he wants without me adding it automatically.

I modified a Navigator template to create my BarNav, but I don't know where to modify the children's liclass.

Basically I would like to :
Parent page (here it's Product)
- header + title
- hand and inside the children's pages which include: header + image + text
& footer (which is already in place).

Thanks to lise I have a content manager working which allows me to add class (for the side of the images) and background colour (thanks to those who created it).

For the moment I'm doing what my tutor told me to do just making children's pages that are accessible in dropdwon.

Translated with www.DeepL.com/Translator (free version)
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Générateur de titre, image, contenu dans gestion du contenu

Post by velden »

So, let's say you have a main menu which has no sub-menus. Then you could use the navigator's number_of_levels parameter to only display one level.

Code: Select all

{Navigator number_of_levels=1 ...}

For the pages you want to include content (text, header, image) of sub-pages you could also use Navigator; NOT to create a menu but to grab the content from the subpages and display it in the way you like (using a custom Navigator template)
(optional) childrenof="" - This option will display only items that are descendants of the selected page id or alias. i.e: {Navigator childrenof=$page_alias} will only display the children of the current page.
For example:

Code: Select all

{Navigator number_of_levels=1 childrenof=$page_alias template=mycustomtemplate}
Use this tag in the PAGE template at the position where you want the dynamic content to appear.

Create a new template in Design Manager of type Navigator::Navigation, name it 'mycustomtemplate' and try this as an example:

Code: Select all

{foreach $nodes as $node}
  <div class="my-dynamic-content">
    <h2>{page_attr page=$node->alias key='title'}</h2>
    <div class="dynamic-text">
      {page_attr page=$node->alias key='content_en'}
    </div>

    <div class="dynamic-image">
      <img src="{uploads_url}/{page_attr page=$node->alias key='my_image'}" alt="" />
    </div>
  </div>
{/foreach}
Also make sure the sub-pages' PAGE TEMPLATE contains a {content_image block='my_image'} tag.
This template can be the bare minimum (because you won't actually use this template for display):

Code: Select all

{content}
{content_image block='my_image'}
I tested the above and it works.
2021-02-08 17_52_48-Window.png
2021-02-08 17_51_54-Window.png
2021-02-08 17_53_38-Window.png
2021-02-08 17_54_23-Window.png
Output
Output
2021-02-08 17_47_46-Window.png (16.29 KiB) Viewed 7114 times
kiwii
New Member
New Member
Posts: 7
Joined: Wed Jan 27, 2021 4:12 pm

Re: Générateur de titre, image, contenu dans gestion du contenu

Post by kiwii »

Ooooooooooh !

It's simple and I was looking in the code where I had to modify.

And so I can make anything I want to appear?
To keep my dropdown so that Internet users can have access, I go through a header page?

Thanks a lot
I finally understood that I don't need to modify all the templates to be able to do what I want.

I'm busy writing down the tips I found for creating a template/content and useful modules. At the end of my internship, I may make a lot of videos to explain how it works and I have a watch planned with the ones from my training.

Thank you very much !!!!!

Translated with www.DeepL.com/Translator (free version)
kiwii
New Member
New Member
Posts: 7
Joined: Wed Jan 27, 2021 4:12 pm

Re: Générateur de titre, image, contenu dans gestion du contenu

Post by kiwii »

Can I still take your time to turn the children's page url into an anchor.

I created an anchor id in the template you helped me build but I can't figure out how to turn the url into an anchor.

I am attaching the template of my browser.

Code: Select all

{* simple navigation *}
{* note, function can only be defined once *}
{* 
  variables:
  node: contains the current node.
  aclass: is used to build a string containing class names given to the a tag if one is used
  liclass: is used to build a string containing class names given to the li tag.
*}

{function name=Nav_menu depth=1}{strip}
{if $depth > 0}
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<ul class="menu-text">
{else}
<ul class="navbar-nav nav-fill ms-auto me-auto mb-2 mb-lg-0 d-flex justify-content-around">
{/if}

  {foreach $data as $node}
    {* setup classes for the anchor and list item *}
    {assign var='liclass' value='nav-item'}
    {assign var='aclass' value='nav-link'}

    {* the first child gets a special class *}

    {* the last child gets a special class *}

    {if $node->current}
      {* this is the current page *}
      {assign var='liclass' value=$liclass|cat:' active'}
      {assign var='aclass' value=$aclass|cat:' active'}
    {/if}

    {if $node->parent}
      {* this is a parent of the current page *}
      {assign var='liclass' value=$liclass|cat:' active parent'}
      {assign var='aclass' value=$aclass|cat:' active parent'}
    {/if}

    {if $node->children}
      {assign var='liclass' value=$dropdown-li|cat:' dropdown'}
      {assign var='aclass' value=$dropdown-item|cat:' dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false"'}
    {/if}

    {* build the menu item node *}
    {if $node->type == 'sectionheader'}
      <li class='sectionheader {$liclass}'>{$node->menutext}
        {if isset($node->children)}
          {Nav_menu data=$node->children}
        {/if}
      </li>

    {else if $node->type == 'separator'}
      <li class='separator {$liclass}'><hr class='separator'/></li>
    {else}

      {* regular item *}
      <li class="{$liclass}">
        <a class="{$aclass}" href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if}>{$node->menutext}</a>
        {if isset($node->children)}
          {Nav_menu data=$node->children}
        {/if}
      </li>

    {/if}
  {/foreach}
</ul>
</div>

{/strip}{/function}

{if isset($nodes)}
{Nav_menu data=$nodes depth=0}
{/if}
I guess this is the part I have to change.

Code: Select all

     {* regular item *}
      <li class="{$liclass}">
        <a class="{$aclass}" href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if}>{$node->menutext}</a>
        {if isset($node->children)}
          {Nav_menu data=$node->children}
        {/if}
      </li>
But nothing happens when I change

Code: Select all

 <a class="{$aclass}" href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if}>{$node->menutext}</a>
By

Code: Select all

 <a class="{$aclass}" href="#{page_attr page=$node->alias key='alias'}"{if $node->target ne ""} target="{$node->target}"{/if}>{$node->menutext}</a>
thanks for your explanations
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Générateur de titre, image, contenu dans gestion du contenu

Post by velden »

One way to approach this is using the Navigator template you already have:

Code: Select all

{foreach $nodes as $node}
  {$anchors[] = "<a href=\"#{$node->alias}\">{$node->menutext}</a>"}{* build an array of anchor links *}
  <div class="my-dynamic-content" id="{$node->alias}">
    <h2>{page_attr page=$node->alias key='title'}</h2>
    <div class="dynamic-text">
      {page_attr page=$node->alias key='content_en'}
    </div>

    <div class="dynamic-image">
      <img src="{uploads_url}/{page_attr page=$node->alias key='my_image'}" alt="" />
    </div>
  </div>
{/foreach}

{$anchors=$anchors scope=parent}{*make sure the variable is available in the calling template*}
Check the first line in the foreach loop and the very last line of the template.

Then in the page template:

Code: Select all

{strip}
	{process_pagedata}
{/strip}<!doctype html>
<__html lang="{cms_get_language}">

<head>
	<title>{title} - {sitename}</title>
	{metadata}
	{cms_stylesheet}
</head>

</__body>
	<header id="header">
		<h1>{sitename}</h1>
	</header>

	<nav id="menu">
		{Navigator assign=myMenu}
	</nav>

	<section id="content">
		<h1>{title}</h1>
		{content}
{Navigator number_of_levels=1 childrenof=$page_alias template=mycustomtemplate assign=myOutput}{*assign the output to a variable*}

{* first build the anchor navigation based on the $anchors variable from the Navigator template *}
<ul>
{foreach $anchors as $anchor}
  <li>{$anchor}</li>
{/foreach}
</ul>

{$myOutput}{* display the output here *}
	</section>
<__body>

</__html>
Note that this is a working example but there may be other and/or better ways to do this. It also depends on the layout you need etc.
It's also an example to show you how flexible CMSMS is together with Smarty.
kiwii
New Member
New Member
Posts: 7
Joined: Wed Jan 27, 2021 4:12 pm

Re: Générateur de titre, image, contenu dans gestion du contenu

Post by kiwii »

Thank you very much for your explanations.
I was a bit scared when my tutor told me he was working with CMSMS, I had never heard of it.

But now that you've explained what I needed to know, I feel like I'll be able to create templates quite easily.

I've just put your explanation into practice to create a Navigator where my anchors are in a dropdown.

And I believe the blog is yours? Thank you for your work.

I'm slowly but surely starting to get the hang of CMSMS and you may see me answering questions soon.

Again thank you very much for your help.

I will put the matter to rest.
Post Reply

Return to “French - Français”