# Changing the product title to custom field

**URL:** <https://forum.shopware.com/t/changing-the-product-title-to-custom-field/99632>\
**Category:** Shopware 6 (English)\
**Tags:** general, programming, templates--design\
**Created:** [10. Mai 2023 um 11:39 UTC](https://forum.shopware.com/t/changing-the-product-title-to-custom-field/99632 "2023-05-10T11:39:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![killah-keezy](https://avatars.discourse-cdn.com/v4/letter/k/8e7dd6/32.png) [@killah-keezy](https://forum.shopware.com/u/killah-keezy)\
**Post date:** [10. Mai 2023 um 11:39 UTC](https://forum.shopware.com/t/changing-the-product-title-to-custom-field/99632/1 "2023-05-10T11:39:01Z")

</div>

Our shopware is connected to our winstore through API which is why our product name is inherited from the stock system. This sometimes causes for names like „934919da“ which is confusing for the customer.

I created a custom field for product type to add a custom name. Changing the code to anything „lorem ipsum“ works, but when I try to retrieve the custom field, it doesn’t work.

```auto
{% block page_product_detail_headline_inner %}
    {% block page_product_detail_name_container %}
        <div class="col product-detail-name-container">
            {% block page_product_detail_name %}
                <h1 class="product-detail-name"
                    itemprop="name">
     {{ page.product.customFields.custom_productname_|default(page.product.translated.name) }}
                </h1>
            {% endblock %}
        </div>
    {% endblock %}

    {% block page_product_detail_manufacturer %}
        {% if page.product.manufacturer %}
            <div class="col-md-auto product-detail-manufacturer">
                {% block page_product_detail_manufacturer_inner %}
                    {% block page_product_detail_manufacturer_link %}
                        <a href="{{ page.product.manufacturer.link }}"
                           class="product-detail-manufacturer-link"
                           rel="noreferrer noopener"
                           target="_blank"
                           title="{{ page.product.manufacturer.translated.name }}">
                            {% if page.product.manufacturer.media %}
                                {% block page_product_detail_manufacturer_logo %}
                                    <img src="{{ page.product.manufacturer.media|sw_encode_media_url }}"
                                         class="product-detail-manufacturer-logo"
                                         alt="{{ page.product.manufacturer.translated.name }}"/>
                                {% endblock %}
                            {% else %}
                                {% block page_product_detail_manufacturer_text %}
                                    {{ page.product.manufacturer.translated.name }}
                                {% endblock %}
                            {% endif %}
                        </a>
                    {% endblock %}
                {% endblock %}
            </div>
        {% endif %}
    {% endblock %}
{% endblock %}

```

'm really new to shopware, only have basic limited knowledge of coding but usually know my way around. I hope anyone can tell me what’s going wrong. I double checked the correct technical name. the custom field is a text field, connected to Product entity.

I tried Changing the default {{ page.product.translated.name }} to {{ page.product.customFields.custom\_productname\_|default(page.product.translated.name) }}

I also tried {{ page.product.translated.customFields.custom\_productname\_|default(page.product.translated.name) }}

---

<div class="post-metadata">

**Author:** ![TimWB](https://avatars.discourse-cdn.com/v4/letter/t/8e7dd6/32.png) [@TimWB](https://forum.shopware.com/u/TimWB)\
**Post date:** [31. Mai 2024 um 06:45 UTC](https://forum.shopware.com/t/changing-the-product-title-to-custom-field/99632/2 "2024-05-31T06:45:47Z")

</div>

Do you found a solution ?

---

<div class="post-metadata">

**Author:** ![Dennis\_Konoppa](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/dennis_konoppa/32/27245_2.png) [@Dennis\_Konoppa](https://forum.shopware.com/u/Dennis_Konoppa)\
**Post date:** [7. Juni 2024 um 11:00 UTC](https://forum.shopware.com/t/changing-the-product-title-to-custom-field/99632/3 "2024-06-07T11:00:13Z")

</div>

I would recommend to set the product name to a variable and then use the null-coalescing operator (??) or `is not null` call from twig to check if the custom field has a value and only use `product.translated.name` as a fallback

```auto
{% block page_product_detail_headline_inner %}
    {% set productName = page.product.translated.name %}
    {% if page.product.customFields is defined and page.product.customFields.custom_productname_ is not null %}
        {% set productName = page.product.customFields.custom_productname_ %}
    {% endif %}

    {# use the variable where ever you need it: {{ productName }} #}
{% endblock %}

```

Maybe also the naming of the customField (with trailing „\_“) is a problem.  
You can alternatively try to get the custom field’s value with the array key notation:

```auto
{% block page_product_detail_headline_inner %}
    {% set productName = page.product.translated.name %}
    {% if page.product.customFields is defined and page.product.customFields['custom_productname_'] is not null %}
        {% set productName = page.product.customFields['custom_productname_'] %}
    {% endif %}

    {# use the variable where ever you need it: {{ productName }} #}
{% endblock %}

```
