Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#16 2011-07-01 02:02:43

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,477

Re: rah_replace - Search and replace

Your idea in #13 works. I’ve adapted it to my needs:

<txp:output_form form="head" />
	<body id="<txp:section />">
		<div id="wrapper">
			<txp:rah_replace from="http://domain.de" to="">
				<txp:output_form form="slider" />
			</txp:rah_replace>
			<section>
			<txp:if_section name="impressum,kontakt">
				<h1>normal title</h1>
				<txp:article limit="1" sort="position asc" form="artikel" />
			<txp:else />
				<txp:rah_replace from="http://domain.de" to="">
					<h1><txp:if_section name="xy">XY title<txp:else />Normal title</txp:if_section></h1>
					<txp:article limit="1" sort="position asc" form="artikel" />
				</txp:rah_replace>
			</txp:if_section>
			</section>
			<txp:rah_replace from="http://domain.de" to="">
				<txp:output_form form="nav" />
				<txp:output_form form="footer" />
			</txp:rah_replace>
		</div>
	</body>
</html>

It could be that in my first version the HTML5 element <section> interferes with <txp:if_section>. I don’t know it.

Offline

#17 2011-07-01 02:37:43

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_replace - Search and replace

GugUser wrote:

It could be that in my first version the HTML5 element <section> interferes with <txp:if_section>.

Markup has no effect to server-side Textpattern tags, the element isn’t interfering. It’s all about the nesting of the tags. A block needs to be closed on the same level as it was opened. An open parent container tag can not be closed inside a child block.

In your first version you had structure outline is similar to:

<foo>
	<bar>
		</foo>
	</bar>

Such block nesting isn’t possible. Closing foo should be outside bar:

<foo>
	<bar>
	</bar>
</foo>

Offline

#18 2011-07-01 03:23:07

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,477

Re: rah_replace - Search and replace

That was the reduced scheme of my first code:

<txp:rah_replace from="http://domain.de" to="">

	HTML group 1

	<txp:if_section name="kontakt">
		</txp:rah_replace>
	</txp:if_section>

	HTML group 2

	<txp:if_section name="kontakt">
		<txp:rah_replace from="http://domain.de" to="">
	</txp:if_section>

	HTML group 3

</txp:rah_replace>

My intention was that the three HTML groups 1-3 are within one rah_relace, except in the section “kontakt” in which the HTML group 2 is excluded. That would be possible with HTML elements, but not with closing and opening Textpattern tags.

Thank you Els and Gocom for your answers and comments.

Offline

#19 2012-02-06 14:02:44

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,702
GitHub

Re: rah_replace - Search and replace

Hi Jukka – a hopefully easy question if you’re around and reading this thread: I’d like to be able to remove everything between <txp:rah_replace> and </txp:rah_replace>, primarily so I can leave comments in a form/page/etc without it being seen on the front end and reduce load times. Is there a wildcard operator for from in this instance?

Thanks in advance!

Offline

#20 2012-02-06 14:56:26

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,181
Website GitHub

Re: rah_replace - Search and replace

HI Pete,

I usually use <txp:hide> ... your memory dump here ... </txp:hide> for this.


TXP Builders – finely-crafted code, design and txp

Offline

#21 2012-02-06 15:12:27

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,702
GitHub

Re: rah_replace - Search and replace

Hi Jakob – perfect, thank you very much.

Offline

#22 2012-02-28 15:24:28

towndock
Member
From: Oriental, NC USA
Registered: 2007-04-06
Posts: 335
Website

Re: rah_replace - Search and replace

I have a site requirement to replace every other instance of a word – not every instance as normal use of rah_replace would be.

Example: If cat were on the page four times, I need the 2nd and 4th instances to become dog.

Is there a simple tweak to rah_replace that would get this done?

Offline

#23 2012-02-28 18:52:57

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_replace - Search and replace

towndock wrote:

Is there a simple tweak to rah_replace that would get this done?

Sorry, no, not exactly.

Offline

#24 2012-02-28 20:21:02

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,316

Re: rah_replace - Search and replace

towndock wrote:

Example: If cat were on the page four times, I need the 2nd and 4th instances to become dog.

Reminds me of zebra stripes. You could set up such an if_variable conditional around your replacing arrangements. No, don’t even try :P

Last edited by uli (2012-02-28 20:25:58)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#25 2012-02-28 21:08:27

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: rah_replace - Search and replace

towndock wrote:

Example: If cat were on the page four times, I need the 2nd and 4th instances to become dog.

Mmm… I have a vision of a combo of rvm_counter, txp:variable and if_variable and at least two instances of rah_replace… and maybe some smd_query and smd_if to finish it off… ;)

Offline

#26 2012-02-28 21:37:30

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_replace - Search and replace

Ugh, breaking these bubbles. I’m a meanie.

Els wrote:

I have a vision of a combo of rvm_counter, txp:variable and if_variable and at least two instances of rah_replace…

Sorry, but unfortunately, not going to work. You can’t effect rah_replace’s search-and-replace routine in shape or any form. You will need sub-string replacing that has movable pointer, which isn’t what rah_replace does. It always replaces all occurrences, and not even words, i.e. catwomen becomes dogwomen.

Only way you could even theory make it work with rah_replace is to create sub-strings prior to running rah_replace by splitting each words and then joining the results back together. In which point rah_repleace becomes obsolete as you already have individual words to do 1on1 replacing (no search needed).

and maybe some smd_query and smd_if to finish it off… ;)

I don’t see none of those, as it stands, doing it either. Smd_query has no relation to the case at all. It builds DB queries and that is it.

Last edited by Gocom (2012-02-28 21:39:48)

Offline

#27 2012-02-28 21:57:29

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: rah_replace - Search and replace

Gocom wrote:

Sorry, but unfortunately, not going to work.

Haha, not a surprise :) I didn’t think very hard about it. Just curious, is something like this complete nonsense?

<txp:variable name="dogs" value="0" />
<txp:rah_replace from="dog<!-- 2 -->,dog<!-- 4 -->,dog<!-- 6 -->" to="cat,cat,cat">
   <txp:rah_replace from="dog" to='dog<!-- <txp:adi_calc name="dogs" add="1" display="1" /> -->'>
      text with dogs goes here
   </txp:rah_replace>
</txp:rah_replace>

To answer my own question, yes, I expect it is ;)

Offline

#28 2012-02-28 22:26:06

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_replace - Search and replace

Els wrote:

Just curious, is something like this complete nonsense?

Yes.

Offline

#29 2012-02-28 22:28:39

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: rah_replace - Search and replace

Gocom wrote:

Yes.

Thank you. I can let go now ;)

Offline

#30 2012-02-28 23:18:47

towndock
Member
From: Oriental, NC USA
Registered: 2007-04-06
Posts: 335
Website

Re: rah_replace - Search and replace

Thank you all for having a try at this. I might just have to let it go too…

Offline

Board footer

Powered by FluxBB