We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33238
    • 388 Posts
    Hello I would like to know how can I use a Template Tag for example [[*pagetitle]] or a setting value [[++setting]] as default value in a Template Variable?

    The TV is an Input Type: Text

    The idea is have the TV input fields in the manager already filled with Template Tags values, the user will decide if use the default value or edit it, right now is showing the [[*TemplateTag]] format but not the real value.

    Thank you very much.
      --
      ysanmiguel.com
      • 17301
      • 932 Posts
      Edit the template variable and under input options you can enter a default value. Just put your [[*pagetitle]] tag in there.
        ■ email: [email protected] | ■ website: https://alienbuild.uk

        The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
        • 33238
        • 388 Posts
        Quote from: lkfranklin at Aug 25, 2017, 01:46 PM
        Edit the template variable and under input options you can enter a default value. Just put your [[*pagetitle]] tag in there.

        LK, mate, that is exactly what I did but didn't work, see link image:

        https://drive.google.com/file/d/0B4qE5lYwheXbN3BIYzVmWkxVazg/view?usp=sharing

        Any other idea?

        Thank you!
          --
          ysanmiguel.com
          • 38783
          • 571 Posts
          I think that is what I would expect to see in the Manager.

          But if you then call that template variable into your public facing content on a web page (not in the manager) it should process the TV and display the actual page title.
            If I help you out on these forums I would be very grateful if you would consider rating me on Trustpilot: https://uk.trustpilot.com/review/andytough.com

            email: [email protected] | website: https://andytough.com
            • 33238
            • 388 Posts
            Quote from: andytough at Aug 27, 2017, 01:26 PM
            I think that is what I would expect to see in the Manager.

            But if you then call that template variable into your public facing content on a web page (not in the manager) it should process the TV and display the actual page title.

            Yes I think it will display it, but I need to display the content of the pagetitle inside the manager area, so the client don't need to fill every single field in every page.

            Any suggestions about how can I solve this?

            Thank you very much!
              --
              ysanmiguel.com
              • 4172
              • 5,888 Posts
              can't you just do something like that in your template:

              [[*yourTV:default=`[[*pagetitle]]`]]


              and give a hint in the TV - description, that the pagetitle is used, as long, as the TV is empty?

              If you really want to show the parsed value of a tag, you will need to create a custom-TV-input-type, which parses the default-value before showing the manager-form. Its not that difficult.
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 33238
                • 388 Posts
                Quote from: Bruno17 at Aug 29, 2017, 09:24 AM
                can't you just do something like that in your template:

                [[*yourTV:default=`[[*pagetitle]]`]]


                and give a hint in the TV - description, that the pagetitle is used, as long, as the TV is empty?

                If you really want to show the parsed value of a tag, you will need to create a custom-TV-input-type, which parses the default-value before showing the manager-form. Its not that difficult.

                Bruno your first solution make sense and it's easy to implement. I think the right way might be the custom TV but I will need to do around 20 or more different fields, so I think I will use the first one.

                But if you don't mind and just to close the post with a solution, can you give me an example of the custom TV?

                Thanks as always!
                  --
                  ysanmiguel.com
                  • 33238
                  • 388 Posts
                  Quote from: Bruno17 at Aug 29, 2017, 09:24 AM
                  can't you just do something like that in your template:

                  [[*yourTV:default=`[[*pagetitle]]`]]


                  and give a hint in the TV - description, that the pagetitle is used, as long, as the TV is empty?

                  If you really want to show the parsed value of a tag, you will need to create a custom-TV-input-type, which parses the default-value before showing the manager-form. Its not that difficult.

                  Bruno your first solution make sense and it's easy to implement. I think the right way might be the custom TV but I will need to do around 20 or more different fields, so I think I will use the first solution.

                  Thanks as always!
                    --
                    ysanmiguel.com
                    • 42562
                    • 1,145 Posts
                    Solution 1. use MODX things to parse your tags
                    https://docs.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/template-variables/bindings/eval-binding
                    https://docs.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/template-variables/bindings/chunk-binding

                    If this gives silly issues, move on to #2

                    Solution 2. Use a tiny plugin
                    The plugin on OnDocFormRender, will check if the TV input field is empty. (note, this is not a TRUE default TV value)
                    But f you have the TV reset button then it is true DOM default value
                    If empty, fill it up with the pagetitle of current resource (if current resource is not a New one)
                    <?php
                    $tvId = 20;
                    $defaultTVvalue = "";
                    
                    //Alter Resource TV default/value
                    //Plugin fires at OnDocFormRender
                    
                    // if($mode == "upd"){
                    if($resource){
                      $defaultTVvalue = $resource->get("pagetitle");
                    }
                    
                    $modx->regClientStartupHTMLBlock('
                    <script>
                       Ext.onReady(function() {
                        // var tv = document.getElementById("tv'.$tvId.'");
                        var tv = Ext.get("tv'.$tvId.'");
                        var tvDef = Ext.get("tvdef'.$tvId.'");
                    
                        //Note upon save, this tv will have a real value in Database
                        if(tv){
                          tvValue = tv.dom.value;
                          tv.dom.value = tvValue || "'.$defaultTVvalue.'";
                        }
                    
                        //If you have that squiggly thing for TV refresh, the value will be set
                        if(tvDef){
                          tvDefValue = tvDef.dom.value;
                          tvDef.dom.value = tvDefValue ||  "'.$defaultTVvalue.'";
                        }
                       });
                    </script>
                    ');
                      TinymceWrapper: Complete back/frontend content solution.
                      Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                      5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
                      • 42562
                      • 1,145 Posts
                      If for 20+ TVs, just do a tiny loop, done!
                        TinymceWrapper: Complete back/frontend content solution.
                        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.