Note de ce sujet :
  • Moyenne : 0 (0 vote(s))
  • 1
  • 2
  • 3
  • 4
  • 5

news : afficher le titre de la news comme titre de la page et + encore
#34

Ça fait longtemps que le gabarit des news contient la variable canonical par défaut {assign var='canonical' value=$entry->canonical} et {process_pagedata} ne sert plus à rien. La partie concernant ce sujet est obsolète (elle date de 5 ans...).

Pour la V2, les variables des sous-gabarits ne seront plus disponibles dans les gabarits parents (dernière version stable de Smarty). Pour que cela soit à nouveau possible, il faut ajouter scope=global lors de l'assignation de la variable (voir le lien vers le post de Calguy au sujet de l'avancement de la V2 que tu nous as donné aujourd'hui ici Wink).
Citation :In CMSMS 1.x it was assumed and documented that all smarty variables were available at all time, and never disappeared. If you created a variable (lets say 'page_title' in a module template called from the {content} tag that was called from within the </__body> section of your page template, that variable {$page_title} would be available within the <head> section of your page template.

Unfortunately, that is no longer true without explicit action by you. In smarty (now that CMSMS is using an un-modified version of Smarty), sub templates create their own scope. And there is a hierarchy of templates. Variables are copied from parent scopes into child scopes, but are not copied from the child to the parent. Making a smarty variable persistent across multiple scopes requires explicit action by the site developer (specifically you).

Fortunately, it is relatively easy to copy a local variable in a sub template, into a global variable for use in the parent, or other peer templates. And we have added a new smarty plugin to the core to help even more.

If you remember the stock News detail template there was a line such as this:
Code:
{assign var='canonical' value=$entry->canonical}

That created a smarty variable called 'canonical' that was then used in the <head> portion of the page template to create the <link rel="canonical"> tag.
Because of the new smarty scoping methodology, that syntax now looks like this:
Code:
{assign var='canonical' value=$entry->canonical scope=global}


Additionally, the {share_data} plugin will allow you to specify numerous local variables that should be copied to the local scope. i.e:
Code:
{share_data scope=global vars='page_title,canonical,page_description'}


CMSMS uses smarty sub-templates extensively. The most obvious ones are the {content} tags, module templates, like {News}, {Search}, or {Navigator}. However the three portions of the page template (above the HTML tag, from </__body> down, and the head section) are each individual sub templates. Thus, without explicit action variables created in the top section are now not available in the body.
Répondre


Messages dans ce sujet

Atteindre :


Utilisateur(s) parcourant ce sujet : 1 visiteur(s)