No possibility to specify a script tag to modify variables in erb files

Infos:

i want to customize a simple variable in a basic erb file (ticket-update.erb) in this case it is the variable #{recipient.fullname}
here i would get the full name, but i want to customize the output so that i get the first name and then only 2 letters of the last name with a dot. these two letters should also be written in caps format.

i have tried to save the respective variable using a simple <script> tag and to achieve the desired behavior using the split method in the script tag. however, it is not possible for me to create the script tag, or the script tag does nothing.

i have no experience with coffescript and erb, but i do have experience with javascript. How can I achieve this desired behavior? is it possible in the respective erb file or do I have to cache this in another variable in another file?

thanks for the suggestions!

  • Used Zammad version: 5.4.1

Code Snippet:

plain code:

<div>Hallo #{recipient.fullname},</div>
<br>
<div>
ticket (#{ticket.title} from #{ticket.customer.longname}) was "<b>#{current_user.longname}</b>" changed.
</div>
<% if @objects[:article] %>
  <div>
  Information:
  <blockquote type="cite">
    <br>
    #{ticket.articles.first.body}
    <br>
  </blockquote>
  </div>
<% end %>
<br>
<% if @objects[:article] %>
  <div>
  Information:
  <blockquote type="cite">
  #{article.body_as_html}
  </blockquote>
  </div>
<% end %>
<br>

what I tried:

<script>
	var edit = #{recipient.fullname}
	var edit_ = "it works"
</script>

Ticket: (#{ticket.title})

<script><p> {edit} </p></script>
<script><p> #{edit} </p></script>
<script><p> edit </p></script>
<p> edit </p>
<p> {edit} </p>
<p> #{edit} </p>



<script><p> {edit_} </p></script>
<script><p> #{edit_} </p></script>
<script><p> edit_ </p></script>
<p> edit_ </p>
<p> {edit_} </p>
<p> #{edit_} </p>

<div>Hallo #{recipient.fullname},</div>
<br>
<div>
ticket (#{ticket.title} from #{ticket.customer.longname}) was "<b>#{current_user.longname}</b>" changed.
</div>
<% if @objects[:article] %>
  <div>
  Information:
  <blockquote type="cite">
    <br>
    #{ticket.articles.first.body}
    <br>
  </blockquote>
  </div>
<% end %>
<br>
<% if @objects[:article] %>
  <div>
  Information:
  <blockquote type="cite">
  #{article.body_as_html}
  </blockquote>
  </div>
<% end %>
<br>

Expected behavior:

Hallo Max MU.

Actual behavior:

Hallo Max Mustermann

Hi @du7ri.

I suggest to get at least a little bit familiar with Ruby and ERB. :slight_smile:

<% shortened_last_name = recipient.lastname[0..1].upcase %>

Then you should be able to use shortened_last_name in the ERB file. To output it, use #{shortened_last_name}.

1 Like

And btw. @du7ri, your version of Zammad is pretty outdated. You should update it as soon as possible.

1 Like

sorry for the new question but is it possible when i read an html part to split it using the <p> and </p> tags. because with the way you wrote it, i tried in vain. isn’t there the possibility to use the split function. Sorry I’m not very good at ruby, I’m not from the track either

Sorry, I don’t get it.

i have to admit i am more in the angular typescript area. but i thought that it is certainly possible to simply insert a script part into an erb file in which you can perform simple split operations of strings. unfortunately this does not work. is such a thing even possible in erb? because some sources refer to tags in erb files. however, this has no effect on me.

i want to include this script part in the ticket-update.erb file, if such a thing is possible at all. here i want to split the string as already mentioned.

As already mentioned in post 2, it’s possible.