We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7914
    • 137 Posts
    I am using getResources to build a list of people on a page.
    I set up TV’s to serve as Name, address, phone etc. I also have a bio TV.

    Some people have a bio filled out, others do not. For the ones that do, I want to display a button "Read Bio".

    My getResources call looks like:
    [[!getResources? &parents=`[[*id]]` &showHidden=`1` &includeTVs=`1` &processTVs=`1` &tpl=`person_summary_tpl`]]
    


    My person_summary_tpl looks like:
    <div class="person-summary">
    	<img src="[[++site_url]][[+tv.person_photo]]" class="photo" width="100" alt="[[+tv.person_name]]" />
    	<p><strong>[[+tv.person_name]]</strong><br>
    	[[+tv.person_address]]<br>
    	[[+tv.person_city_state_zip]]<br>
    	<a href="mailto:[[+tv.person_email]]">[[+tv.person_email]]</a></p>
    	<p>[[!include? &file=`person_bio.php`]]</p>
    	
    	<div class="clearall"> </div>
    </div> 
    


    I had planned on writting a snippet to check if there was a value for the current person. The catch is, I’m not sure how to (or where to) grab the current document id that getResources is using to build it’s list. So, something like this would be my snippet:
    [[!include? &file=`person_bio.php` &person_id=`getResourcesID would go here`]]
    


    Then somehow in my person_bio.php file, I’d grab the ID. That way I could look up any TV value:
    $resource_id = $modx->resource->get('id');
    
    // check if there is a bio available
    $person_bio = $modx->getObject('modTemplateVar',array('name'=>'person_bio'));   // get the tv object
    $person_bio_value = $person_bio->getValue($resource_id); // get the value from the tv
    


    Or, maybe I’m making this entirely too difficult. Which, could be the case as well.
      • 4172
      • 5,888 Posts
      try this:
      <div class="person-summary">
      	<img src="[[++site_url]][[+tv.person_photo]]" class="photo" width="100" alt="[[+tv.person_name]]" />
      	<p><strong>[[+tv.person_name]]</strong><br>
      	[[+tv.person_address]]<br>
      	[[+tv.person_city_state_zip]]<br>
      	<a href="mailto:[[+tv.person_email]]">[[+tv.person_email]]</a></p>
      	<p>[[!If? &subject=`[[+tv.person_bio]]` &operator=`notempty` &then=`[[+tv.person_bio]]`]]</p>
      	<div class="clearall"> </div>
      </div> 
      
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 30585
        • 833 Posts
        Couple of observations?

        Since each person has their own page, why not use the [[*content]] field to write the person’s bio? and the [[*introtext]] field to display an excerpt of that bio in the getResources call?

        This is what the tpl should look like with that minor change:

        <div class="person-summary">
        	<img src="[[+tv.person_photo]]" class="photo" width="100" alt="[[+tv.person_name]]" />
        	<p><strong>[[+tv.person_name]]</strong><br>
        	[[+tv.person_address]]<br>
        	[[+tv.person_city_state_zip]]<br>
        	<a href="mailto:[[+tv.person_email]]">[[+tv.person_email]]</a></p>
        	<p>[[+introtext:default=`[[+content:ellipsis=`400`]]`]]</p>
        	
        	<div class="clearall"> </div>
        </div> 

        Also, if you include a <base href="[[++site_url]] " /> in your template’s header just before you load any stylesheets and javascript files, you can use relative paths when adding things like images, files etc.

        So instead of src="[[++site_url]][[+tv.person_photo]]" you’d get : src="[[+tv.person_photo]]"

        You don’t really need to write a snippet to do what is already possible with tricks most of us use.


        Does this answer your question?

          A MODx Fanatic
          • 7914
          • 137 Posts
          Hi Treigh, thanks for your reply. It kind-of helps.

          Instead of displaying a person’s actual bio, I want to display a button that says "Read Bio". From that button, I am going to use an overlay to bring up the person’s full information. (somehow) smiley
          So really, I need to check if there is a value to the [[+tv.person_bio]].

          This is incorrect syntax, but this is kind of the logic I am not sure how to achieve:
          if ( [[+tv.person_bio]] != null )
          {
              $out = '<a href="persons-page.html"><img src="my-button"></a>'; // this will link to the person's full page/bio
          }
          else
          {
              // person does not have a bio, so do nothing
          }
          


          Thank you for your time, I really appreciate the help.

          *EDIT
          Sorry Bruno17, I didn’t see your post. I will work with that and see if I can come up with something. Thank you for your post.

            • 30585
            • 833 Posts
            Much like what Bruno17 suggested, this should help:

            [[!If?  
               &subject=`[[+tv.person_bio]]`  
               &operator=`notempty`  
               &then=`<a href="persons-page.html"><img src="my-button" /></a>`  
               &else=``  
            ]] 


            You would place this wherever you would want the link displayed. This should normally output the link only if the person_bio tv is not empty. Otherwise, nothing is printed at the insertion point.

            This solution supposes that you have the if snippet installed in your MODx install.

              A MODx Fanatic
              • 7914
              • 137 Posts
              The if snippet! All of the sudden I think the clouds are parting and sun is shining!

              Thank you both for the suggestions, I appreciate the help (and time). Time to roll up the sleeves and put the pieces together.
                • 33976 ☆ A M B ☆
                • 571 Posts
                Hi,

                output modifiers could also be usefull here
                [[!+tv.person_bio:notempty=`<a href=…`]]

                But i would recommend reading this nice article about MODx placeholders, caching & parsing order

                Hope it helps
                  • 11055 ☆ A M B ☆
                  • 3,112 Posts
                  @Romain,
                  that’s a wonderful experiment.

                  Would you add another one?
                  As rtrash stated in here, we can also trick the document’s object directly.
                    Rico
                    Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                    MODx is great, but knowing how to use it well makes it perfect!

                    www.virtudraft.com

                    Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

                    Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

                    Maintainter/contributor of Babel

                    Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
                    • 33976 ☆ A M B ☆
                    • 571 Posts
                    Goldsky > smiley there are loads more on rtfm.modx.com if you want
                    You could also make your own snippet and use them as modifiers… MODx is made to make you love it more than the day before wink

                    Edit : just in case, an example of a snippet used as output modifier is available on this thread