Question

What's the best way to extend the attribute href programmatically in Typo3?

The links were setted by RTE like

<a class="download" target="_blank" href="fileadmin/ablage/test_material/pdf_1.pdf">

and shall be changed to

<a class="download" target="_blank" href="fileadmin/ablage/test_material/pdf_1.pdf#zoom=100">
Was it helpful?

Solution

Untested code:

you could try to add the section to the parameter

lib.parseFunc_RTE.tags.link.typolink.parameter.append = TEXT
lib.parseFunc_RTE.tags.link.typolink.parameter.append {
  value = #zoom=100
  if.equals.data = parameters:0
  if.equals.substring = -3,3
  if.value = pdf
}

or you can try to use "section"

lib.parseFunc_RTE.tags.link.typolink.section.cObject = TEXT
lib.parseFunc_RTE.tags.link.typolink.section.cObject {
  value = zoom=100
  if.equals.data = parameters:0
  if.equals.substring = -3,3
  if.value = pdf
}

BUT the most important issue is the "if" statement. I assume that the first parameter is the name of the file (i do not remember). The last 3 charachters should be "pdf". If you use DAM you need to retrieve the UID and get the filetype from there.

Just a rought guess, this could give you a hint, which params do you have:

lib.parseFunc_RTE.tags.link.typolink.parameter.append = TEXT
lib.parseFunc_RTE.tags.link.typolink.parameter.append {
  data = parameters : allParams
  htmlSpecialChars = 1
  wrap = ?debug=|
}

Just a side note: this would be affect all RTE fields!

OTHER TIPS

If there is a fixed class for that link, you could use jQuery...

jQuery(document).ready(function(){
  $('.download').each(function(){
    var linkhref = $(this).attr('href');
    $(this).attr('href', linkhref + '#zoom=100');
  });
});

This code do it.

parseFunc_RTE.tags.link.typolink.parameter.append = TEXT
parseFunc_RTE.tags.link.typolink.parameter.append {
    value = #zoom=100
    if.equals.data = parameters : allParams
    if.equals.substring = -3,3
    if.value = pdf
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top