We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40147
    • 3 Posts
    I have a bunch of resources that are "products".

    It is my intention to create a page on my site that lists some of these products (that have been identified via a template variable).

    I tried creating a symlink in the "Featured Products" container, which refers to a product. I then tried outputting this using getResources; but none of the template variables get carried over.

    Is there a better way to achieve this? I don't want to have to "duplicate" the content.

    the produts are in containers but these are dynamic, so I can't really use `parents` of getResources; as I'd have to constantly be updating this.
    • Sounds like you need a separate data model for storing/managing your products. Then you have reusable data that can be rendered in views however you want.

      That said, if you give the SymLink the same Template as the Product, you should be able to get the inherited Template Variable values when rendering the Resource itself. getResources however does not support this currently.
      • I use a custom output modifier to show the symlink target content in getResources. If the resource is not a symlink it will just spit out the normal content. It could easily be built upon to show TV's as well.

        $resource = $modx->getObject('modResource', $input );
        $content = $resource->get('content');
        
        if($resource->get('class_key') == 'modSymLink') {
        $linkedresource = $modx->getObject('modResource', $content);
        $content = $linkedresource->get('content');
        }
        
        return $content;
          • 36722
          • 101 Posts
          @pyrographics Care to elaborate on this at all? I got it working for only content. I tried with TVs and created a new output filter using the getTVVale API but it seemed to break the normal one.

          My use case is. I have 2 contexts, I'm symlinking products from one to build out a secondary listing on a new domain. so you update one it updates everywhere. Titles work, intro text works, but not images attached via TVs in the get resources call.
            Shawn Himmelberger
            Himmelberger Design
            https://himmdesign.com/services/website-development/modx"" target="_blank" rel="nofollow"> MODx Web Design | https://himmdesign.com/services/website-development/modx"" target="_blank" rel="nofollow"> MODx Web Development
            • 41428
            • 22 Posts
            Hi Everyone

            Hopefully this might help some of you, I expanded @pyrographics original idea. I've written 2 Output Modifier snippets for getting symlink values using getResources:

            Get TV Value (getSymTV)
            //Output Modifier: [[+tv.tv-name:getSymTV=`[[+id]],tv-name`]]
            
            $options = explode(',',$options);
            $symID = $options[0];
            $tvName = $options[1];
            
            if(is_numeric($symID) && !empty($tvName)){
              $resource = $modx->getObject('modResource', $symID);
              $content = $resource->getTVValue(''.$tvName.'');
            
              if($resource->get('class_key') == 'modSymLink') {
              	$linkedID = $resource->get('content');
              	$linkedresource = $modx->getObject('modResource', $linkedID);
              	$content = $linkedresource->getTVValue(''.$tvName.'');
              }
            }
            
            return $content;
            


            Get Resource Field (getSymField)
            //Output Modifier Content only: [[+content:getSymField]]
            //Output Modifier: [[+field:getSymField=`[[+id]],field`]]
            
            $options = explode(',',$options);
            
            if(is_numeric($input)){
            	$id = $input;
            	if($options[0] == ""){
            		$field = 'content';
            	}else{
            		$field = $options[0];
            	}
            }else{
            	$id = $options[0];
            	$field = $options[1];
            }
            
            //check if numeric id, to prevent WSOD.
            //Return input if not (allows returning of content from non-symlink resources
            if(is_numeric($id)){
            
              $resource = $modx->getObject('modResource', $id );
              $content = $resource->get(''.$field.'');
               
              if($resource->get('class_key') == 'modSymLink') {
              	$linkedID = $resource->get('content');
              	$linkedresource = $modx->getObject('modResource', $linkedID);
              	$content = $linkedresource->get(''.$field.'');
              }
            
              return $content;
            
            }else{
            
              return $input;
            
            }
            


            Kyle