Problem with viewtemplate code

Hello everyone.
I’m struggling with some code and can’t get it to work. I don’t know how many interactions I’ve made, and GPT Chat can’t seem to help me.

I have three fields defined: “resolved_by”, “url”, “medium”.
What I want is for the following to be displayed in the tiddler header using a tiddler labeled with $:/tags/ViewTemplate:

After the text “Resolved by:”, I want the values in the “resolved_by” field to be displayed. It can be one or more, and they can also contain compound words with spaces in between. If the field is empty, I want it to say “Not Found”.
Then, if the “medium” field has a value, I want it to display:
If I don’t have a “url”, I want the value of “medium” to be displayed after the text “in”.
If I have “url”, I want it to combine the “url” and “medium” fields as follows: [[medium|url]]
If the “medium” field is empty, then nothing should be added after the “resolved_by” value (this is something I wanted but isn’t in the code yet).

This is the code I’m using, but I can’t get it to work.

<$set name="resueltopor" tiddler=<<currentTiddler>> field="resuelto_por" />
    <$set name="url" tiddler=<<currentTiddler>> field="url" />
    <$set name="medio" tiddler=<<currentTiddler>> field="medio" />

    <!-- Mostrar Resuelto por -->
    ''Resuelto por'': 
    <$list filter="[<resueltopor>is[blank]]">
      Desconocido
    </$list>
    <$list filter="[<resueltopor>!is[blank]]">
      <$list filter="[enlist<resueltopor>trim[]]" variable="item">
        <$text text=<<item>> />
        <$list filter="[<item>!match[<resueltopor>last[]]]">, </$list>
      </$list>
    </$list>

    <!-- Mostrar medio si no hay URL -->
    <$list filter="[<url>is[blank]]">
        <<medio>> </$list>

    <!-- Mostrar medio si hay URL -->
			<$list filter="[<url>!is[blank]]">
				en [[<<medio>>|<<url>>]]
			</$list>

Thanks in advance.

Try this out:

Spanish version:

''Resuelto por'':
<$list filter="[enlist{!!resuelto_por}]" join=", " emptyMessage="//Desconocido//">{{!!title}}</$list>
<% if [{!!medio}!match[]] %>
	<% if [{!!url}match[]] %>
		en {{!!medio}}
	<% else %>
		en <a href={{!!url}} target="_blank" rel="noopener noreferrer">{{!!medio}}</a>
	<% endif %>
<% endif %>

English version:

''Resolved by'':
<$list filter="[enlist{!!resolved_by}]" join=", " emptyMessage="//Unknown//">{{!!title}}</$list>
<% if [{!!medium}!match[]] %>
	<% if [{!!url}match[]] %>
		in {{!!medium}}
	<% else %>
		in <a href={{!!url}} target="_blank" rel="noopener noreferrer">{{!!medium}}</a>
	<% endif %>
<% endif %>

The ChatGPT code has some significant issues, so I tried to rely primarily on your written description. Let me know if I misunderstood your goals.

  • I’m assuming the url field will contain the URL for an external site, so I hard-coded it as an external link.
  • I also replaced “not found” with “unknown” in the English version; I think it makes a little more sense in context. :slightly_smiling_face:

Thank you for providing the description, by the way! It’s much easier than trying to guess what ChatGPT was thinking.

1 Like

“Thinking”?! Ha ha ha! :imp:

1 Like

You know, I was going to put “thinking” in quotes, and then I thought I ought to be polite… :wink:

Thank you so much, Emily!!!

It does what I wanted, thanks to your code. I’ll have to review it carefully to fully understand it and be able to use it for other things.

Regarding GPT Chat, I know it’s not a good idea, but “sometimes” it works. Other times, it’s better to say nothing… Although where it helps is to explain already written code so I can understand it.

And thank you for the translation of the code. When I translated the message, I forgot to adjust the fields and comments in the code. :sweat_smile: Of course, “unknown” is the equivalent of “desconocido” in Spanish.

Here’s proof that it works correctly.

Best regards.

3 Likes

Wise, given one day it may become our robot overlord :nerd_face: