On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • How do I get a "general" value in YAMS, instead of a language specific?
    I want to give an ID to the "body" (for CSS selection) but if I use 'pagetitle' it changes with the language. I was looking for the 'Internal Name' Document Object, but it doesn't seems to exhist.
    Thank you

    This question has been answered by binaerstrom. See the first response.

    [ed. note: andrearicci last edited this post 7 years, 5 months ago.]
      MODx evo 1.5~1.6 ✪ Apache v 2.2.22 ✪ PHP v 5.3.10 ✪ MySQL v 5.1.61
      <°'iiii);
    • Hi,

      I had a similar problem and got across with the MODx API (http://wiki.modxcms.com/index.php/API:getTemplateVarOutput). I created a little snippet (it's really just a basic function call) that takes two values (docID and TVname) and returns the value of the TV. I used this to get the link_attributes from a child document on the parent document.

      <?php
      
      /* 
      *  Snippet call example: [[getTVvalue? &tvName=`link_attributes`, &docID=`13`]]
      *  &tvName -> name of the TV (e.g. link_attributes)
      *  &docID -> document ID (e.g. 13)
      */
       
      $tvValStr = $modx->getTemplateVarOutput($tvName, $docID);
      return ($tvValStr[$tvName]);
      
      ?>
      


      Just create a new snippet add the code and place the snippet call inside your template.


      Cheers,
      Boris
      • Thank you, I just found tthat I can simply use the GetField snippet, that should be installed by default.
        The default call [[GetField]] already gives me the pagetitle of the current document, but can retrive other fields.
        Now in my CSS I can point a document by its id, without language worries, even with yams:
        <body id="[[GetField]]" class="[[GetTemplateName]]">

        If not using Yams it would be simply:
        <body id="[*pagetitle*]" class="[[GetTemplateName]]">
        .
        As you can see I also give the body a class based on the template, so I can easilly vary styles from my CSS witouth having to touch the templates any more.
        I specially like this:
        <body id="[*alias*]" class="[[GetTemplateName]] [*layout*] [[GetField? &field=`alias` &parent=`1`]]">
        [ed. note: andrearicci last edited this post 7 years, 5 months ago.]
          MODx evo 1.5~1.6 ✪ Apache v 2.2.22 ✪ PHP v 5.3.10 ✪ MySQL v 5.1.61
          <°'iiii);
        • discuss.answer
          Wow, didn't know that snippet smiley
          That looks quite perfected!

          Thank you too!