We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29914
    • 0 Posts
    Hi, I’m building my first site in MODx (Revo 2.1.1), and am seeking some advice regarding hyperlinks.

    This page http://supamarket.co.uk/index.php?id=3 is using a template which is used by 9 pages (resources). Currently, only the title text of the product acts as a hyperlink but is there a way of making each rectangle containing the product image and title text a hyperlink (i.e. the 9 grey gradient areas)? I can see how this can be achieved using 9 different templates but is there a clever way of being able to do this by sharing the same template? Hope this is clear.

    Thanks in advance.

    Matt
      • 35094
      • 25 Posts
      I was doing something similar so I hope this helps.

      Instead of putting each product into a div why don’t you make a list / menu using Wayfinder?

      I was then using this for my row template

      <li><a href="[[+wf.link]]" title="[[+wf.title]]" [[+wf.attributes]]><img class="thumbnail" src="assets/[[+thumbnail]]"><span>[[+wf.linktext]]</span></a>[[+wf.wrapper]]</li>
        • 22427
        • 793 Posts
        Not that izzy’s proposal is not worth a thinking - but you just need to wrap the link element around the div (and avoid also repeting the link several times).
        Instead of
        <div class="productHome" id="Home1">
        <h4><a href="index.php?id=12">Joseph Joseph</a></h4>
        <h4 class="proddesc"><a href="index.php?id=12">Hands on Salad Bowl</a></h4>
        <h4 class="prodprice"><a href="index.php?id=12">£30</a></h4>
        <img src="assets/templates/homepage/images/jj-hands-on-salad-bowl-small.jpg" />
        </div>
        

        use this code:
        <a href="index.php?id=12">
        	<div class="productHome" id="Home1">
        	<h4>Joseph Joseph</h4>
        	<h4 class="proddesc">Hands on Salad Bowl</h4>
        	<h4 class="prodprice">£30</h4>
        	<img src="assets/templates/homepage/images/jj-hands-on-salad-bowl-small.jpg" />
        	</div>
        </a>


        Edit:
        Probably this code will not validate - because [tt]<a>[/tt] as an inline element shouldn’t contain a blockelement like <div> . Nevertheless it works in Firefox 4.
        (I didn’t check other browsers). Checked IE 8: The link is working, but the cursor will not change to a pointing hand unless you apply explicitely the rule [tt]cursor: pointer;[/tt] to the [tt]<a>[/tt] element.
          • 29914
          • 0 Posts
          Quote from: ottogal at Jun 24, 2011, 01:11 AM

          Not that izzy’s proposal is not worth a thinking - but you just need to wrap the link element around the div (and avoid also repeting the link several times).
          Instead of
          <div class="productHome" id="Home1">
          <h4><a href="index.php?id=12">Joseph Joseph</a></h4>
          <h4 class="proddesc"><a href="index.php?id=12">Hands on Salad Bowl</a></h4>
          <h4 class="prodprice"><a href="index.php?id=12">£30</a></h4>
          <img src="assets/templates/homepage/images/jj-hands-on-salad-bowl-small.jpg" />
          </div>
          

          use this code:
          <a href="index.php?id=12">
          	<div class="productHome" id="Home1">
          	<h4>Joseph Joseph</h4>
          	<h4 class="proddesc">Hands on Salad Bowl</h4>
          	<h4 class="prodprice">£30</h4>
          	<img src="assets/templates/homepage/images/jj-hands-on-salad-bowl-small.jpg" />
          	</div>
          </a>


          Edit:
          Probably this code will not validate - because [tt]<a>[/tt] as an inline element shouldn’t contain a blockelement like <div> . Nevertheless it works in Firefox 4.
          (I didn’t check other browsers). Checked IE 8: The link is working, but the cursor will not change to a pointing hand unless you apply explicitely the rule [tt]cursor: pointer;[/tt] to the [tt]<a>[/tt] element.

          Many thanks to both of you for replying. Ottogal, do you know how I would implement this, given that the content of the boxes (i.e. products) will change over time, so the URL it points to will change? I assume there is a way of not having to hard code this. Each of the 9 boxes is a template variable where the user can write a title and insert a picture through the CMS. Do I need to set up another TV as a URL?? Sorry, I’m just learning MODx so this is brand new to me.

          Thanks
          Matt
            • 22427
            • 793 Posts
            you could just switch the link to be just inside the div
            Of course!
            But you need to wrap the [tt]img[/tt] element into a [tt]div[/tt] so that the link will work also outside of the image (to the left or the right of it).
            You might also be able to do away with the div completely and put a width and height onto the <a> tag as well as your rounded corners, background img, etc. So the <a> would adopt the class and id you now have assigned to the div.
            I’m not sure if the rounded corners technique used here is working with a non-block element like <a>.
            Also, it’s probably just personal preference, but having three <h4>s in a row seems odd to me. I would use spans with classes as hooks for the styling.
            I agree. I would just use <p> instead of <h4>, with appropriate styling for it.
              • 22427
              • 793 Posts
              Ottogal, do you know how I would implement this, given that the content of the boxes (i.e. products) will change over time, so the URL it points to will change? I assume there is a way of not having to hard code this. Each of the 9 boxes is a template variable where the user can write a title and insert a picture through the CMS.
              Hardcoding the nine [tt]div[/tt]s for your products in your template and using an own Template Variable for every product is really unflexible.
              That can be done in a more dynamic way using Wayfinder (as izzy said) or getResources.

              To achieve that you would have to create a single resource for each product, based on a common template, say "prodtemplate". They all have to be children of the page id=3 on which you want to show the links.

              You create Template Variables "pbrand", "pdesc", "pprice" and "pimage" of type text and assign them to the template "prodtemplate".

              To insert a new product the manager user just has to create a new resource (child of id=3) with the template "prodtemplate" and edit the individual product information in the Template Variables.

              On the page containing the links (or in its template) you replace all your code for the nine divs by the Wayfinder call, f.e.
              [[!Wayfinder? &startId=`3` &rowTpl=`prodTpl` ]]


              By default the Wayfinder output is a unordered list ( [tt]ul[/tt] ) where the parameter [tt]&rowTpl[/tt] contains a chunk for the [tt]li[/tt] elements (like in izzy’s example above).

              But Wayfinder is so flexible that you can keep your [tt]div[/tt]s instead (perhaps modified as in the previous discussion). So the chunk [tt]prodTpl[/tt] for the parameter [tt]&rowTpl[/tt] , could look like this:
              <div class="productHome">
              	<a href="[[+wf.link]]" title="[[+wf.title]]" [[+wf.attributes]]>
              	<p>[[+pbrand]]</p>
              	<p class="proddesc">[[+pdesc]]</p>
              	<p class="prodprice">[[+pprice]]</p>
              	<div><img src="assets/templates/homepage/images/[[+pimage]]" /></div>
              	</a>
              </div>
              
              (You see that we can not - and must not - use anymore id="Home#" .)

              The point is: Wayfinder will control dynamically the output of the products, that is if you add a new product it will be automatically inserted in the page of links (and automatically sorted in in the wanted order, default is by menuindex).

              You would not be limited to nine products per page. Using Floats in the styling you also could achieve a flexibility in the number of products per row, dependent on the width of the view port. And so on ...

              Have a try. Best wishes!
              ottogal


                • 22427
                • 793 Posts
                Citing myself:
                To achieve that you would have to create a single resource for each product, based on a common template, say "prodtemplate". They all have to be children of the page id=3 on which you want to show the links.
                Of course your individual resources for the products already exist (id=12,13,2,14,...). So just be sure they all are children of the overview page for the links, the id of which is needed as the [tt]&startId[/tt] value for the Wayfinder call.

                BTW: Meanwhile I think it would be easier to use the snippet [tt]getResources[/tt] - but the basic idea would be the same.
                  • 29914
                  • 0 Posts
                  Quote from: ottogal at Jun 25, 2011, 02:56 AM

                  Citing myself:
                  To achieve that you would have to create a single resource for each product, based on a common template, say "prodtemplate". They all have to be children of the page id=3 on which you want to show the links.
                  Of course your individual resources for the products already exist (id=12,13,2,14,...). So just be sure they all are children of the overview page for the links, the id of which is needed as the [tt]&startId[/tt] value for the Wayfinder call.

                  BTW: Meanwhile I think it would be easier to use the snippet [tt]getResources[/tt] - but the basic idea would be the same.

                  Thanks very much for all of your helpful advice, Ottogal. I’d previously struggled with Wayfinder but will have another go with your advice. I’ll look into getResources too. Thanks again, Matt.