System-asset linking to system-data-structure

birwin's Avatar

birwin

11 May, 2016 05:59 PM

Hi There,

I'm writing a Velocity macro to list all of our reusable content pieces on a page.

The macro works, however, I've tried to include a link to the asset itself, and this is where I'm running into an issue.

Example Code:

#set($contactSpifs = $_XPathTool.selectNodes($contentRoot, "//system-block/system-data-structure[@definition-path='page-spifs/contact-spif']"))
<h1>Contact Spifs</h1>

<div class="col col-100">
#foreach($spif in $contactSpifs)
    <div class="spifcontainer">
        #renderSpif($spif)
        
      #set($link = "" + $spif.parent.parent.getChild('path').value + "")
        
        <a href="[system-asset]${link}[/system-asset]">Link</a>
    </div>
#end
</div>

I've tried using the link re-writing, I've tried the system asset in the setting of the $link variable, and within the anchor. In the preview, I get a result like so:

<a href="[system-asset]/_training/common/spifs/Contact Spif - Example[/system-asset]">Link</a>

but in the rendereg html I get <a href="">Link</a>

Any thoughts, tips or tricks are appreciated.

Thanks!

  1. 1 Posted by Ryan Griffith on 11 May, 2016 07:09 PM

    Ryan Griffith's Avatar

    Hi Brendon,

    What you have should definitely work. Curious, but have you tried using the link instead of path? If you are generating these links within a different Site, you will need cross-Site links in order for them to be linked to the correct asset.

    Thanks!

  2. 2 Posted by birwin on 11 May, 2016 07:23 PM

    birwin's Avatar

    The link didn't work for me either, but when I looked at using the link, it was taking the parent folder's link and then appending the data definitions name so I assumed that was the issue.

    I've included a sample xml and heres an example of the script

    #set($contactSpifs = $_XPathTool.selectNodes($contentRoot, "//system-block/system-data-structure[@definition-path='page-spifs/contact-spif']"))
    <h1>Contact Spifs</h1>
    
    <div class="col col-100">
    #foreach($spif in $contactSpifs)
        <div class="spifcontainer">
            #renderSpif($spif)
            #set($link = ""  + $spif.parent.parent.getChild('path').value  + "")
            <a href="[system-asset]${link}[/system-asset]">Link</a>
        </div>
    #end
    </div>
    
  3. 3 Posted by Ryan Griffith on 16 May, 2016 01:30 PM

    Ryan Griffith's Avatar

    Hi Brendon,

    Very interesting about using the link. Testing locally, I was not seeing what you described (with the Data Definition name). Here is what I am getting:

    <a href="[system-asset]site://students.wlu.ca/_cascade/asset factories/spifs[/system-asset]">Link</a>
    

    Were you able to get things working?

    Thanks!

  4. Tim closed this discussion on 27 Jun, 2016 08:56 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac