Templates & Custom Fields

Hi,

How can I point directly in a template to a particular custom field?

If I put {% for field in custom_fields %}{{ field.text }}{% endfor %} in a part of the template I get all the custom fields. Let’s say that I have two custom fields. I need to have the first one in a part of the page and the other one in another. How can I do this?

I dont know much in HTML but i know where you position something affect it display. if a Table is started, you can enter a custom field in there to display among the items in that table. A code will end the table and maybe another table started. You can insert another custom field in there as well.

Hi,

I want to had a custom title if the custom fields “header” is populated. I tried both:

{% if custom_fields[‘Header’] != null %}{{custom_fields[‘Header’]}}{% else %}{{ title }}{% endif %}

{% if custom_fields.Header != null %}{{custom_fields.Header}}{% else %}{{ title }}{% endif %}

but it always shows me the {{ title }}

any help?

@Davide i don’t really think it will work but try this

{% for field in custom_fields %}
{% if (field.label !=‘DATE OF ARRIVAL’) %}{% continue %}{% endif %}

assuming the custom field name is DATE OF ARRIVAL

I found the soultion
{% for field in custom_fields %}{% if (field.label !=‘Header’) %}{% continue %}{% endif %}
{% if field.text != null %}{{field.text}}{% else %}{{ title }}{% endif %}
{% endfor %}

Can you display an image of your achievement?, it can help other users

I’m still working on it… i get the value if it’s populated but if it’s not i don’t get the title.

Need some help:

I wrote those lines

                    {% for field in custom_fields %}
                    {% if (field.label !='Header') %}{% continue %}{% endif}
                    {% if field.text != nil %}{{field.text}}{% else %}{{ title }}{% endif %}
                    {% endfor %}

I don’t know why is always showing me field.text and not title even if the field.text is empty,

@Davide try ’ ’ instead of nil , and tell me if it works

No… it’s always empty. I found a workaround that I don’t like so much:

                    {% for field in custom_fields %}{% if (field.label !='Header') %}{% continue %}{% else %}{{field.text}}{% endif %}
                    {% endfor %} {{title | replace: "Invoice", "" }}

Instead of

{{ title }}

you should put

{% for field in custom_fields %}{% if (field.label !=‘Header’) %}{% continue %}{% else %}{{field.text}}{% endif %}
{% endfor %} {{title | replace: “Invoice”, “”}}

So the final result is that, if it is an invoice then, if a custom field exist and it’s called “Header” it will show the new title in the head of the template.

In order to avoid to display again in the footer this custom field I made same changes:

    {% for field in custom_fields %}
    {% if (field.label !='Header') %}
    <tr>
        <td colspan="99">
            <div style="font-weight: bold; padding-top: 20px">{{ field.label }}</div>
            <div>{{ field.text | newline_to_br }}</div>
        </td>
    </tr>{% continue %}{% endif %}
    {% endfor %}

IF SOMEONE KNOWS HOT TO MAKE THIS WORK (IT DOESN’T SHOW TITLE IF “ELSE”) PLEASE EXPLAIN HOW:

{% for field in custom_fields %}{% if (field.label !=‘Header’) %}{% continue %}{% endif %}
{% if field.text != null %}{{field.text}}{% else %}{{ title }}{% endif %}
{% endfor %}

If you can explain clearly what you are trying to achieve and where you are trying to achieve it with the help of some images then maybe i can help. your posts are too confusing.

Thanks @sharpdrivetek,

Right now in “sales invoices” I have a custom field that is called “Header”.

In the template I want that,
IF
(a) there is a custom field.label called “Header” (in the purchase invoices right now I don’t have it but who knows…) AND (b) the custom field.text is not empty
THAN
it displays custom field.text
ELSE
it displays {{ title }}

You have to replace the codes as below.

<td style="font-weight: bold; font-size: 32px">
{% if title == 'Invoice' %}{% for field in custom_fields %}{% if (field.label == 'Header') %}{% if (field.text !='') %}{{ title | replace: title, field.text }}{% endif %}{% endif %}{% endfor %}{% else %}{{ title }}{% endif %}
</td>

Scroll down and add the following just after {% for field in custom_fields %}

{% if (field.label == 'Header') %}{% continue %}{% endif %}

Tell me if it works.

Always the same problem… if the field is empty it doesn’t show anything!

you might have already messed up the default template code. try copying a fresh template and then modify.

I’ve started from a fresh one but… as always if the field is empty it doesn’t show anything!

@sharpdrivetek

It seems like field.text !=‘’ doesn’t work

try

{{field.text | strip_newlines | rstrip}}

that should clear any empty characters

`{%- assign custom_variable = field.text -%} was reading that it should also trim all empty characters, tho did not test it yet

I do usually deal with custom variables in beginning of template by assigning them to variables like:

{% for field in custom_fields %}
    {% if field.label == 'Business Area' %}
        {% assign business_area = field.text | strip_newlines | rstrip %}
    {% endif %}
    {% if field.label == 'Notes' %}
        {% assign notes = field.text %}
    {% endif %}
{% endfor %}

so then I can use it later like

{% if business_area == 'Custom Business' &}
  {{business_area}}
{% endif %}

p.s Also custom field have to be marked as printable otherwise it will not be available

1 Like

This worked for me: if you create a field “FAO” (must be marked “Show custom field on printed documents”, you can refer to it as:

{{ custom_fields.FAO }}

But be careful not to create tho custom fields with the same name for two different objects (e.g. “Customer” and “Sales Invoice”)