Manipulate field:header of content element (old: How to replace a character in header with a select result?)

StackOverflow https://stackoverflow.com/questions/23498351

  •  16-07-2023
  •  | 
  •  

質問

I'm using the tx_news extension. When the plugin is used on a page and a header is set including a specific character, I want to replace this character with the number of news articles existing. For example an editor maintains there are # articles for your selected category and the user should see there are 8 articles for your selected category. I hope you got, what I want to accomplish.

My TypoScript:

lib.anzahlNews = CONTENT
lib.anzahlNews { 
  table = tx_news_domain_model_news
  select {
    selectFields = COUNT(title) AS anzahl
    pidInList = 23
    where = archive = 0
  }  
  renderObj = COA
  renderObj.wrap = <span class="item_count"> | </span>
  renderObj {
    10 = TEXT
    10.field = anzahl
  }
}
lib.stdheader {
    # some ohter unrelated stuff I'm doing


    stdWrap {
        # clear old datawrap
        dataWrap >

        innerWrap.cObject = COA
        innerWrap.cObject {
            5 = TEXT
            5.value = <header class="csc-header

            10 = TEXT
            10 {
                value = news-headline
                noTrimWrap = | ||
                if {
                    value = news_pi1
                    equals.field = list_type
                }
            }

            15 = TEXT
            15.value = ">

            20 = TEXT
            20 {
                value = | foo # bar
                stdWrap.replacement {
                    10 {
                        search.char = 35
                        replace < lib.anzahlNews
                    }
                }
                if {
                    value = news_pi1
                    equals.field = list_type
                }
            }

            25 = TEXT
            25.value = </header>
        }
    }
}

So I have two issues here:

  1. I am unable to actually get the number out of my content element.
  2. Only the # between foo and bar is replaced. (Results in foo CONTENT bar.) But the hash in the actual headline (the pipe) isn't replaced at all.

Sorry in advance, because I'm a mere beginner to TypoScript.

Can someone please show me where I'm wrong and show me the direction? Thank you very much.


// edit (2014-05-07 14:09):

I found out, that replace only expects Strings - therefor I see "CONTENT", in my result. I now try to use stdWrap.split to split the content of the header-field at the # and appanding the content from my lib.anzahlNews like this:

20 = TEXT
20 {
    value = | foo # bar
    stdWrap {
        split {
            token.char = 35

            # rendering of content
            cObjNum = 1 || 2
            1.current = 1
            1.wrap = |
            1.append < lib.anzahlNews
            2.current = 1
            2.wrap = |
        }
        if {
            value = news_pi1
            equals.field = list_type
        }
    }
}

That works so far, as it resolves my first issue of getting the wanted value at all. But the second issue still remains, that the actual content of the header-field isn't touched at all.

I need to manipulate the value of the header-field itself. How can I accomplish that?

役に立ちましたか?

解決

according to the tsref replacement comes with a stdWrap as well. so you might wanna try this:

....20 = TEXT
....20 {
     replacement {
          10 {
               search.char = 35
               replace.cObject < lib.anzahlNews
          }
     }
}

but since this above doesn't replace the # in your header text, try applying your second attempt to h2 headlines:

lib.char_replace {
         token.char = 35
         cObjNum = |*||*| 1 || 2
         1.current = 1
         2 < .1
}

lib.stdheader.10.2.split < lib.char_replace
lib.stdheader.10.2.split.1.append < lib.anzahlNews

maybe you get this working for all headlines with this:

lib.stdheader.10.setCurrent.split < lib.char_replace
lib.stdheader.10.setCurrent.split.1.append < lib.anzahlNews
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top