We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24731 ☆ A M B ☆
    • 211 Posts
    Hi all,

    I am exhausted from trying to sort this out on my own without any success so I would appreciate any help.

    I have created a TV I will use on each document to specify a name (this will be a folder name).

    I created a chunk to get the value of this TV so I can access it later on from a different TV which is the one executing the Snippet I created for this.

    I am trying this code:

    @EVAL return $modx->runSnippet("ImageSlideTags", array ("sld_fld" => @CHUNK sld_foldr_path ));


    If I try

    @CHUNK sld_foldr_path


    It works perfectly, it displays me the folder name I want. If I try:

    @EVAL return $modx->runSnippet("ImageSlideTags", array ("sld_fld" => "somevalue" ));


    The snippet executes correctly and works as expected. I just have not been able to get them to work together so I can achieve what I want.

    Basically I created a small snippet that searches for a list of images within a folder. These images are used to dynamically generate a slideshow for each section of the website.

    What I want is to only require from my customer to enter a folder name and everything done automatically. Already achieved it by hardcoding the values, I just need to get the @EVAL to read the Chunk value so it can work. Or if there is a way to get the TV value from another TV even better.

    I appreciate any assistance.

    Regards,
    Jose R. Lopez
      • 22303 MODX Staff
      • 10,725 Posts
      Why not just do....
      @EVAL return $modx->runSnippet("ImageSlideTags", array ("sld_fld" => $modx->getChunk('sld_foldr_path') ));
      ?
        • 24731 ☆ A M B ☆
        • 211 Posts
        Quote from: OpenGeek at Apr 18, 2007, 11:02 PM

        Why not just do....
        @EVAL return $modx->runSnippet("ImageSlideTags", array ("sld_fld" => $modx->getChunk('sld_foldr_path') ));
        ?

        Thank you, that does include the chunk contents, but without processing the variable. I am only getting the TV inside the chunk as raw content.

        opendir(/home/****/public_html/cms/assets/images/slideshows/[*Page_Img_Slider_Folder*]): failed to open dir: No such file or directory

        Thanks for your help.

        Jose R. Lopez
          • 33372
          • 1,611 Posts
          Er now I’m really confused. Does your chunk contain a TV placeholder ([*Page_Img_Slider_Folder*])? If so, why (since you could use the TV placeholder on it’s own in documents, and you can get the value of the TV in a snippet or TV @EVAL)?

          Maybe if you posted all of your code and a more specific explanation of what you’re doing we could either help figure out why it isn’t working or suggest an alternative method.
            "Things are not what they appear to be; nor are they otherwise." - Buddha

            "Well, gee, Buddha - that wasn't very helpful..." - ZAP

            Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
            • 24731 ☆ A M B ☆
            • 211 Posts
            I think it might be useful if I explain you what I am trying to achieve, perhaps I am not taking the best approach, so any suggestion is greatly appreciated.

            This is the snippet I created:

            <?php
            global $base_url;
            
            // This is the full server path to the document root of your website
            $dir_server_root	=	"/home/****/public_html";
            // This is the path to the slideshow folder
            $dir_img_slideshow	=	$base_url . "assets/images/slideshows";
            // This is the name of the folder which holds specific page images
            $dir_img_name		=	$sld_fld;
            // Composed Dir
            $dir_composed		=	$dir_server_root . $dir_img_slideshow . '/' . $dir_img_name;
            // list of filetypes you want to show
            $allowed_types = array('png','jpg','jpeg','gif');
            
            $dimg = opendir($dir_composed);
            	while($imgfile = readdir($dimg))
            	{
            		if(in_array(strtolower(substr($imgfile,-3)),$allowed_types) && substr($imgfile, 0, 7) != '.thumb_')
            		{
            			$a_img[] = $imgfile;
            			sort($a_img);
            			reset ($a_img);
            		} 
            	}
            $totimg = count($a_img); // total image number
            
            	for($x=0; $x < $totimg; $x++)
            	{
            		// do whatever
            		$slideshowimages .= '<image path="' . $dir_img_slideshow . '/' . $dir_img_name . '/' .$a_img[$x].'" />';
            	}
            
            	return $slideshowimages;
            ?>
            


            I then created a TV which calls the snippet with the folder name it will use to create the code. Here is the file:

            @EVAL return $modx->runSnippet("ImageSlideTags", array ("sld_fld" => "dr/homepage" ));


            The above code works, but I am hardcoding the dir name (path). I need this dynamic for each page by just entering the folder path. Since I am unaware if it is possible to include a TV value inside another, I created a chunk which calls for the TV where I have enabled for editors to insert the path. So what I need is a way to read that data from the chunk.

            Hope it is clearer what I am trying to do.

            I appreciate your help again.

            Regards,
            Jose R. Lopez
              • 33372
              • 1,611 Posts
              OK! I do think that we can probably help you to figure this out now. You probably want to do it a bit differently, since as far as I can tell you’re doing things exactly the opposite of how most people do them in MODx (which is not wrong; it’s creative!).

              You can pass a parameter to a snippet just by using the following syntax:
              [[mySnippet? &parameter=`myValue`]]

              So you don’t need a TV with an eval to do that. What I would do is to store the slideshow folder path in a regular text TV and then just pass its value to the snippet. So if I understand what you want to do correctly, your snippet call would probably be:
              [[ImageSlideTags? &sld_fld=`[*slideshowFolderPath*]`]]

              Also: You don’t need to declare $base_href as a global var and all that; just use something like:
              $modx->config[’base_url’]. "assets/images/slideshows";
              $modx->config[’base_path’]. "assets/images/slideshows";

                "Things are not what they appear to be; nor are they otherwise." - Buddha

                "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

                Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                • 24731 ☆ A M B ☆
                • 211 Posts
                Quote from: ZAP at Apr 19, 2007, 12:41 AM

                OK! I do think that we can probably help you to figure this out now. You probably want to do it a bit differently, since as far as I can tell you’re doing things exactly the opposite of how most people do them in MODx (which is not wrong; it’s creative!).

                You can pass a parameter to a snippet just by using the following syntax:
                [[mySnippet? &parameter=`myValue`]]

                So you don’t need a TV with an eval to do that. What I would do is to store the slideshow folder path in a regular text TV and then just pass its value to the snippet. So if I understand what you want to do correctly, your snippet call would probably be:
                [[ImageSlideTags? &sld_fld=`[*slideshowFolderPath*]`]]

                Also: You don’t need to declare $base_href as a global var and all that; just use something like:
                $modx->config[’base_url’]. "assets/images/slideshows";
                $modx->config[’base_path’]. "assets/images/slideshows";



                Great stuff, I guess I put too much thinking about now as now that you explain it, and considering I spent about 4 hours trying to figure it out, it turned out to be quite simple hehe.

                I guess mind plays game sometimes. I appreciate your help. I will try this out right now and post back results.

                Jose R. Lopez
                  • 24731 ☆ A M B ☆
                  • 211 Posts
                  That was just beautiful, I can now sleep for the rest of the night thanks to you!

                  Worked like a charm!

                  Regards,
                  Jose R. Lopez