We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6769
    • 2 Posts

    I have written a snippet and it works fine but I now want to add the Web Link Attribute field so I can optionally open the link in a new window.

    My current working line of code is $output .= ’<ul><li> <a href="[~’ . $children[$i][’id’] . ’~]" ’ . ’>- ’ . $children[$i][’pagetitle’] . ’</a></li></ul>’;

    I have tried adding $children[$i][’linkattributes’] . into the line in the correct location after the href but it does not make any difference.

    Have I missed something? Apologies if this is a really dumb question that is documented somewhere.

    Also can I use the same syntax to access template variables as I cannot get these to work either?

    Apart from this I am finding MODx very useful and have achieved everthing that I need so far.

    Many thanks

    David

      • 10487 MODX Staff
      • 1,535 Posts
      For the first question, try using (note the underscore): $children[$i][’link_attributes’]

      For the second question, how are you populating the $children array? There are a couple of MODx methods you may be interested in, these are $modx->getDocumentChildrenTVars() and $modx->getDocumentChildrenTVarOutput().

      Both of those methods will retrieve the document children and merge in the TV values for the documents at the same time - the first one giving ’raw’ TV values, while the latter will give you the processed TV values.
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 6769
        • 2 Posts
        Thanks for that - I have got it working now!!!

        I didn’t fully understand and had not included the link_attributes in the call to get the data. I have modified that line as well

        $children = $modx->getDocumentChildren($doc[’id’], 1, 0, ’id, pagetitle, editedon, link_attributes’, $whereClause, $sortBy, $sortDir);

        From what you say I suppose I could just remove the fields parameter to return everything.

        This solves my immediate problem but I will work on getting TVs working as well.

        Thanks again for such prompt responses.

        Best wishes

        David