We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30497
    • 245 Posts
    This must be simple, but I can’t work it out.

    I have a Template variable, and in a Textarea I have:
    <h1>[*longtitle*]</h1>


    This is because, for certain pages, I need to NOT have a H1 heading, but for the majority, I do need it.

    So, the pages I don’t want the H1, I was just hoping to delete the above content from the TV. But, it appears that it is impossible to simply delete my code there and make that TV blank.

    When I have a textarea TV with content in it as above, how do I then make the TV output *no* data in the cases of my choosing?

    Thanks.
      • 7231
      • 4,205 Posts
      The most straight forward method would be to use PHx and have an if statement to show the TV if it has content. Then include the h1 tags directly in the PHx output.

      http://wiki.modxcms.com/index.php/PHx

      But you could also build a snippet to out the TV if it has a value or not as well.
        [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&#39;t know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 30497
        • 245 Posts
        Quote from: dev_cw at Apr 26, 2008, 01:54 PM

        The most straight forward method would be to use PHx and have an if statement to show the TV if it has content. Then include the h1 tags directly in the PHx output.

        http://wiki.modxcms.com/index.php/PHx

        But you could also build a snippet to out the TV if it has a value or not as well.

        thanks for the quick response. The PHx option seems good, but I don’t see how it could work, as it is impossible for me to save a TV without content, when the default is with content. After saving it just automatically switches back to the default content of the TV.

        As for building a snippet, I can’t code php.

        I really don’t want to start using different templates as that will cause me problems with other parts of the site architecture. Is there any other way??
          • 7455
          • 2,204 Posts
          when you delete the value be sure to place a &nbsp; then the tv is not empty and the default value is not set in that tv

          greets Dimmy
            follow me on twitter: @dimmy01
            • 30497
            • 245 Posts
            Quote from: Dimmy at Apr 26, 2008, 03:05 PM

            when you delete the value be sure to place a &nbsp; then the tv is not empty and the default value is not set in that tv

            greets Dimmy

            That just writes &nbsp; on the page unfortunately.
              • 7455
              • 2,204 Posts
              what kind of tv did you use?
              richtext or text?
              if its rich text then just press space but why not use a tex tv that this should work
              I use this trick a lot
                follow me on twitter: @dimmy01
                • 7231
                • 4,205 Posts
                I would add a - to represent the empty state and use PHx to output if it does not match -

                [+phx:if=`[*TvName*]`:is=`-`:then=``:else=`<h1>[*TvName*]</h1>`+]

                or this could also be done as
                [+TvName:is:ne=`-`:show+]


                With a snippet it could be something like this where the snippet call would be [!snipetName? &val=`[*tvName*]`!]
                <?php
                return $val = (isset($val) != "-") ? '<h1>'.$val.'</h1>' : '';
                ?>


                Now if the TV will have any special chars then you would need to access the TV value with the MODx api and input the TV name rather than the placeholder: [!snipetName? &tv=`tvName`!]
                <?php
                $tv = isset( $tv ) ? $tv : "";
                $id = $modx->documentIdentifier;
                $tvValue = $modx -> getTemplateVarOutput( $tv, $id, $published = 1 );
                
                return $tvValue = ($tvValue != "-") ? '<h1>'.$tvValue.'</h1>' : '';
                
                ?>


                None of this is tested but it should give you some idea of ways to proceed. Like with everything in MODx there are many options grin
                  [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&#39;t know what it is.
                  Do you, Mr. Jones? - [bob dylan]
                  • 30497
                  • 245 Posts
                  @Dimmy:
                  I am using a text area, not richtext. I realise the problem is my content being rtl and the manager ltr - so the "&" and the ";" swapped positions on output. I can fix that, but it would still leave a blank line with your method, no? I want the code to not exist. Which brings to dev_cw’s solutions:

                  @dev_cw:
                  Thanks for the examples, they really helped me and I do now have it working perfectly! I installed PHx and modified your example to this -
                  [+phx:if=`[*h1-tv*]`:is=`-`:then=``:else=`[*h1-tv*]`+]

                  and it works just great, and is a very elegant solution, too, for a non-programmer like myself!