We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17617
    • 8 Posts
    Hello there,

    I have a simple question regarding contexts.

    I have setup this contextstructure:
    DomainA
    DomainB
    DomainC

    Then I have setup TVs:
    Domain_A_textcolor
    Domain_B_textcolor
    Domain_C_textcolor

    Now if context DomainA is chosen as WebURL, then Domain_A_color should be chosen for textcolor.
    If context Domain B is chosen as WebURL, then Domain_B_color should be chosen for textcolor.
    .. so on.

    I have loaded my CSS stylesheet as a chunk so I am able to use TVs.

    I thought this is the code to let modx get the contextname and the associated TV.
    However, this is not working:

    [[contextdata?
    &DomainA=`[[*Domain_A_textcolor?]]`
    &DomainB=`[[*Domain_B_textcolor?]]`
    &DomainC=`[[*Domain_C_textcolor?]]`
    ]]

    Any help on this?

    All the Best!
    Luckyred
      • 17617
      • 8 Posts
      Sorry, forgot to upload my own module.

      If someone want to do that create the following snippet:

      $contextkey = $modx->resource->_contextKey;
      $contexts = array('DomainA', 'DomainB', 'DomainC');
      foreach($contexts as $context){
      	if($context == $contextkey && !empty(${$context})){
      		return ${$context};
      	}
      }


      You then can call different contexts by [[contextdata? ...]]