• YAMS - how to retrive a "general" value? [SOLVED] [Solved]#

  • andrearicci Reply #1, 6 months ago

    Reply
    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


  • binaerstrom Reply #2, 5 months, 3 weeks ago

    Reply
    Wow, didn't know that snippet That looks quite perfected!

    Thank you too!


  • binaerstrom Reply #3, 5 months, 3 weeks ago

    Reply
    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


  • andrearicci Reply #4, 5 months, 3 weeks ago

    Reply
    Thank you, I just found tthat I can simply use the GetField snippet, that should be installed by default.
    The default call 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`]]">