4

Not sure if this is possible. For example I have following config:

<xx>
 <yy id="1">
     <zz value="hehe"/>
 </yy>
 <yy id="2">
     <zz value="hehe"/>
 </yy>
 <yy id="3">
     <zz value="hehe"/>
 </yy>
 <yy id="4">
     <zz value="hehe"/>
 </yy>
</xx>

I wonder if I can create one patch config to update the value of zz for all items in the list? Even if a new yy is added in the future?

I imagine it should look like this (I made this up):

<yy id="[[*]]">
    <zz value="newValue"/>
</yy>

Otherwise I need to create a patch for each item yy and whenever a new yy is added, I need to patch it as well.

Thanks!

1 Answer 1

5

It is not possible using the patching mechanism in Sitecore to replace the values of multiple elements using a single patch config statement.

If the values happen to all be the same, and you want to replace them, one possible solution is to make use of sc.variables, e.g.

<sc.variable name="myConfigValue" value="S1t3c0r3" />

You can then make use of this variable in your configuration, for example:

<xx>
 <yy id="1">
     <zz value="$(myConfigValue)" />
 </yy>
 <yy id="2">
     <zz value="$(myConfigValue)" />
 </yy>
 <yy id="3">
     <zz value="$(myConfigValue)" />
 </yy>
 <yy id="4">
     <zz value="$(myConfigValue)" />
 </yy>
</xx>

If you need to change the value, then you can use a patch config to change the value of the variable, e.g.

<configuration xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <sc.variable name="myConfigValue" value="eXp1r13nc3" />
  </sitecore>
</configuration>

As long as any nodes you add later use the variable token, it will get replaced by Sitecore during the patching process.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.