We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36695
    • 47 Posts
    Maybe someone else can replicate the following behaviour and confirm whether a) it's what you would expect and b) is there are way round it?

    I have two templates, "Article" and "Event". For the "Article" template I have assigned a radio TV called "Colours" with options red, green and blue. The default is set to "green". The TV is NOT assigned to "Event".

    I make a document with the Event template, and in its content I try to access the TV with
    [[*Colours]]
    . As the Colours TV is NOT assigned to this template I would expect to get nothing/null back, but instead I get "green" (the default value).

    It happens programmatically too (using getTVValue("Colours")).

    I know an obvious answer is to simply not access that TV from a template that doesn't have it assigned, but in my particular case I was using it as part of a snippet that is used in both templates I was trying to do something like the following, where my "Selection" array is composed of resources that could be using either the Articles or Events template:
    foreach($Selection as $Resource) {
    	
    	$Colour = $Resource->getTVValue("Colours");
    
    	// Here, if the Resource does not have the Colours TV assigned,
    	// I would expect Colour to be null or empty, not the TVs default value.
    	
    	$action = $Colour==='green' ? 'this' : 'that';
    	//etc
    }
    


    Does that make sense?! Do I need to check for a TV's "existence" instead and if so what's the quickest way of doing that?
    Thanks
      • 10208 ☆ A M B ☆
      • 1,780 Posts
      Is there anything surrounding the TV snippet call in the content that might be accessing the other template or another resource's TV? If not, double check that the TV isn't assigned to the template in use. Because it's not possible to access a different template's TV in MODX without assigning the ID of the resource containing the TV value to the TV call. When a template or resource is associated with a TV, the simple TV call

      [[*yourTV]]


      only looks to that resource's TV value by default. If it is blank in the resource, there will be no output. If the TV is not assigned to the template in use, it won't show in the resource, and thus can't be accessed with the simple call. If there is a value in a different resource, regardless of template, it should not grab and output that value with the simple call.

      If Bob was around your snippet may give some clue to why it's doing this and he'd help fix it but I imagine he's close to boarding a plane for Europe soon. Hopefully someone else can check the snippet and tell you why it's grabbing the TV value globally.


      [ed. note: frogabog last edited this post 13 years, 10 months ago.]
        Frogabog- MODX Websites in Portland Oregon
        "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
        Having server issues? These guys have MODX Hosting perfected - SkyToaster
        • 36695
        • 47 Posts
        That's what I would assume. However, it seems that when the TV has a default value, that is fetched regardless of whether or not the TV is related to the template.
        Could you try the setup as described? I've just double-double checked, and it still does the same thing. My templates are empty apart from [[*content]].

        Resource One - Content: [[*MyTV]], Template: TemplateA
        Resource Two - Content: [[*MyTV]], Template: TemplateB

        TV "MyTV" - Input type: Radio, Options: Opt1==1||Opt2==2||Opt3==3, Default: 2, Template Access: TemplateA

        In this case, viewing both Resource One and Resource Two outputs "2", whereas I'd only expect it to show 2 - the default value - on Resource One.
          • 10208 ☆ A M B ☆
          • 1,780 Posts
          Where are you calling the snippet from?
            Frogabog- MODX Websites in Portland Oregon
            "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
            Having server issues? These guys have MODX Hosting perfected - SkyToaster
            • 10208 ☆ A M B ☆
            • 1,780 Posts
            OK, I think it's your snippet that's mucking it up. I don't write snippets and php is still a foreign language to me, so I can't tell you exactly what's wrong but the information in the links below likely will give you a better clue. The Wiki link is Evolution documentation (depreciated) but still valid (just make sure you note the Revo tag syntax of double brackets ([[) instead of Evo).

            http://bobsguides.com/modx-snippet-faq.html
            https://forums.modx.com/index.php/topic,43393.msg259126.html
            http://wiki.modxcms.com/index.php/Creating_Snippets
              Frogabog- MODX Websites in Portland Oregon
              "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
              Having server issues? These guys have MODX Hosting perfected - SkyToaster
              • 22303 MODX Staff
              • 10,725 Posts
              Template Variables that are not assigned to a Template will still render the default value in a Resource with that Template. It is a known behavior, referred to affectionately as "Ronin" TVs (see issue #1852) for an older discussion on the subject.
                • 10208 ☆ A M B ☆
                • 1,780 Posts
                Well, that's all kinds of interesting. The only problem is, as I can see, this TV is actually assigned to a template (template A), while it's being output on template B.

                ???



                  Frogabog- MODX Websites in Portland Oregon
                  "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
                  Having server issues? These guys have MODX Hosting perfected - SkyToaster
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Restated: Template Variables which are not assigned to the Template of a Resource being rendered will still render the default value of the Template Variable, despite it having no relation to that Template. It does not matter if it is attached to another Template or not.
                    • 10208 ☆ A M B ☆
                    • 1,780 Posts
                    OK, the bug thread was slightly confusing. So this means that when calling up a TV in all templates, the resource id of "self" should be defined unless you want it to be global. Correct?

                    [[~id[[*colorTV]]]]
                    (I honestly don't know if this would work, never assigned an ID to a TV in this way)

                    Or maybe?:
                    [[*colorTV? &docid=`[[~id]]`]]


                    Or, should some kind of if statement be used?

                    [[*colorTV]]:isnot=``:then=`[[*colorTV]]`


                    Or, assign the TV to both templates, and allow it to have a blank value as default with an @inherit assigned to a parent?


                      Frogabog- MODX Websites in Portland Oregon
                      "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
                      Having server issues? These guys have MODX Hosting perfected - SkyToaster
                      • 36695
                      • 47 Posts
                      Hi and thanks for the input.
                      I love the name, and now that I know it's not just me I'll find some other way round what I was trying to do.
                      I'm not sure I see the worth in this behaviour other than being able to take advantage of input/output formats, as system/context settings seem a more appropriate way to share data across all resources. It would be great if in the future there were more options for input type for system settings mind.
                      @Frogabog, I'm not entirely sure what you're trying to do, and I think the main lesson is "carry on as before, nothing to see here" unless you are working on a specific case where you're doing something a bit fancy.
                      Thanks again