We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6094
    • 60 Posts
    I am attempting to use Modx for a portfolio site. I’m new at this and not really a programmer so bear with me.

    What I’ve done to this point is created a different page for each portfolio entry. I have a title of the work and descriptions. This is pretty straight forward because I’ve used the forms provided by default. What I would like to be able to do is attach photos of the work and associate them with each page. I have a pretty good grasp of template variables, but I’m thinking there might be a better way that I’m unaware of.

    So lets say I have 5 portfolio pages each representing a different piece of work and I want to associate 5 photos with each of the pages. Will I have to create 25 unique template variables for each of the images and insert them into each page accordingly?

    Any thoughts or techniques I’m unaware of would be greatly appreciated.
      • 7231
      • 4,205 Posts
      Template Variables are the solution for this. When I do portfolio sites I will use a document for each ’work’ and assign as many image TV’s as needed. You can use a plugin like DirectResize to auto generate different sizes if you want as well.

      So lets say I have 5 portfolio pages each representing a different piece of work and I want to associate 5 photos with each of the pages. Will I have to create 25 unique template variables for each of the images and insert them into each page accordingly?
      No. You will create 5 TVs and they can be made available to as many templates as needed. Then you can either insert them in a template directly, or use a snippet to generate the correct output on the fly.
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don't know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 6094
        • 60 Posts
        Thanks for the help.

        Let me make sure I have a good grasp on what you’re saying.

        • I need to create a template for the pages. For now we’ll refer to it as portfolio.
        • Then I need to create a new page for each portfolio entry.
        • Let’s say each page has 5 photos associated with the work. I would then need 5 template variables. We’ll call these [*image1*],[*image2*],[*image3*], etc.
        • Each of these template variables would need to be accessible to the portfolio template.

        Now, if I create portfolio page 1 using the portfolio template and assign an image to the template variable {*image1*], wouldn’t that value be expressed on any additional pages that were created using the portfolio template? For instance when portfolio page 2 is created would it not display the image from portfolio page 1 if [*image1*] were used?

        I hope that makes sense.
          • 26931
          • 2,314 Posts
          Hi there,

          the value for each TV will/can change for each document, so portfolio page 2 will show the image you assign to it on page 2

          cheers, j
            • 7231
            • 4,205 Posts
            The template variables are actually "Custom Document Variables Grouped and Assigned by Templates" so the TV content or value will be tied to the current page. Each document (or page) will have it’s own values for the template variables.

            You can instruct MODx to inherit the TV values from parent documents by using the @INHERIT binding. This is handy for instances where an image is to be carried over from a parent document like a section header.

            Then if you want to create an index page for the portfolio with an image from each job you would use Ditto (or Wayfinder depending on your requirements).
              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don't know what it is.
              Do you, Mr. Jones? - [bob dylan]
              • 6094
              • 60 Posts
              Brilliant!

              Thank you all for your help.
                • 6094
                • 60 Posts
                Sorry, one more.

                I think it’s starting to click for me now.

                So, then based on the above example if I create a chunk and insert a placeholder with [+image1+], and use Ditto pulling from the parent portfolio it will inturn display the template variable value for image1 from every page?
                  • 4310
                  • 2,310 Posts
                  Exactly right wink
                  Enjoy the power of TV’s and Ditto.
                    • 16183
                    • 1,390 Posts
                    While I was learning the ropes the way I got my head round this template variable (TV) concept is that it is a "variable" - meaning it can vary/change... wink

                    Welcome to modx!

                    cheers/k