We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23831
    • 23 Posts
    I just took over a company website that I will be maintaining with MODx CMS... It’s pretty basic and not too flashy. Homepage, and a few subsequent pages.. There are two templates, one for the home page and one for the rest of the pages. When I change the homepage image it changes the rest of them... My question is, how do I set up the documents to view different images corresponding to the page their on (eg; Products page has product picture, staff page has picture of staff) ? The pictures are the same size on every page and instead of setting up 5 different html pages just for the pictures, is there a code to dynamically change the photos with code?

    I use Macbook Pro OS Leopard
    MODx 0.9.6.2?
      • 27330
      • 884 Posts
      that’s a good company if they using modx smiley

      each page has a document in the manager where you can add whatever image you want to have on the page.
      if you have lots of pages you can make TVs with different path to images and select which one is used on each page.

      you just need a new document as you say you have the templates setup already, so it’s a matter of couple clicks to add new page.
        • 24495
        • 407 Posts
        There are many ways:

        With 2 templates you should assign a TV called "pageImg" or so to the templates. If the images are "static" (meaning every category has a unique image) the TV can be built with radio options or list box.
        Read this: http://modxcms.com/creating-a-template-variable.html

        During page/document editing you choose the category in assigned TV.

        In your template can be a snippet call processing the TV’s value like
        <img src="[[getPageImg]]" />


        The snippet getPageImg reads the value of TV and returns the image path needed. An idea for the snippet (raw version):
        <?php
        $id = (isset($id))? $id : $modx->documentIdentifier;
        $pimg = $modx->getTemplateVar('pageImg',"*",$id);
        
        if ($pimg['value'] != '') {
        switch ($pimg['value']) {
        case cat1:
        $output = 'assets/images/cat/cat1.jpg';
           break;
        case cat2:
        $output = 'assets/images/cat/cat2.jpg';
           break;
        case cat3:
        $output = 'assets/images/cat/cat3.jpg';
           break;
        }
        }
        return $output;
        ?>


        Another way is using different templates for each category.