Help with <replace />

Hi.

I'm new to Plone.

I have some content been generate from a .pt file.

And I need to replace just some css rules.

So on a .pt file I have

<div id='myId' class='myTitle and some others css' >
    <p>my content here</p>
</div>

I want to replace the css above (that is coming from the .pt file), so on the theme I put this

 <div id='myId'  class='some others css and a new one'></div>

and on the rules.xml I put.

 <replace attributes="class" css:theme="#myId" css:content="#myId"  />

Quoting the help page (https://docs.plone.org/external/diazo/docs/basic.html#replace)

If you want to replace attributes instead of tags, you can use the attributes attribute to provide a space-separated list of attributes that should be replaced on the matched theme node(s).

I expected that the original div from the content is inserted on the theme but with these new classes.

But the end result is the unmodified div element on the theme.

<div id='myId'  class='some others css and a new one'></div>

I'm doing something wrong? Or I misinterpreted the docs?

Thanks.

Is that valid HTML?

Hi.

It was just a way to express that I used "id" and "classes" without typing id="myId" and class="some other class"

HI @mateus,
It would help us to help you if you shared something closer to the real code.
Once you've done that, I'm sure this can be resolved.

I edited the question, hope it's more clear now.

Thanks.

You need to post your full rules.xml file and index.html so we can make sense of it. A Github repo with your theme package would be even more helpful, in as to provide context.

Your rule seems right, however there are order of operations that may render it unused, or some other rule may be overwriting it (most likely).

I cannot post my code here.

Can you point me to the documentation that explain order or what rule overwrite other rules?

I searched for that and didn't find something.

Thanks.

Diazo order of rules execution is documented here: https://docs.plone.org/external/diazo/docs/basic.html#order-of-rule-execution

1 Like

Are you saying that in your 'final output' You do NOT want to include <p>my content here<p>

If so, can you just replace 'the normal way' and skip the children ?

Note: there is a difference between

css:content 
css:content-children

Order of rules was linked already, thanks @jensens, but it could also be the case that you have another rule operating on the same element, or a container. Try to use the rule in a vanilla Plone site to get it rule working and with that you can confirm you have something masking it in your more complex theme.

I want the same exact component from the content on the theme.

But only with differents classes.

check the docs for diazo examples e.g. modify or add attributes

If you only need to add a class to the element from the content:

  <!-- Add lead class to document description elements. -->
  <replace content="div[@class[contains(., 'documentDescription')]]">
    <div>
      <xsl:copy-of select="attribute::*[not(name()='class')]" />
      <xsl:attribute name="class"><xsl:value-of select="@class" /> lead</xsl:attribute>
      <xsl:apply-templates />
    </div>
  </replace>

Also, check the examples at http://pigeonflight.github.io/lessArcane/.

Hi.

I know that using xsl it's possible to solve the problem.
In fact it was the way that I solved.

What I want to understand is why that specific "attributes" attribute in replace don't work.
I made a mistake? the code is broken? it was removed and not documented? it has some specific situation to use?

I spent a lot of time to find this xsl alternative, while the documentation says that with just this command would solve my problem.

you code has 284 characters and attributes="class" has 18.

I like the golang philosophy, the less code you type, less bug your software has.

Thanks.

@tmassman

Also, check the examples at lessArcane

Thanks. this guide looks very good, definitely will spend some time on it

In the Diazo Docs:

Note: As with rules working on tags, if the named attribute(s) do not exist on the both the theme and content nodes, nothing will happen. If you want to copy attributes regardless of whether they exist on the theme node(s) or not, you can use instead.

It's working on Tags, not on Attribute Selectors like on your Example. You should use XSLT :wink: