<p>At some unknown point, there was a change in the way this plug-in works. The output of getUrl() only works for certain types of links. If the link is an entry or asset, the ID is returned instead.</p>
<p>So I did this:</p>
<pre><code>          {% switch column.button.type %}
            {% case 'entry' %}
              {% set theUrl = craft.entries().id(column.button.value).one().url() %}
            {% case 'asset' %}
              {% set theUrl = craft.assets().id(column.button.value).one().url() %}
            {% default %}
              {% set theUrl = column.button.getUrl() %}
          {% endswitch %}
</code></pre>

CC BY-SA 4.0
2023-04-19T07:33:15.480Z
I don't think that's the normal behaviour. `getUrl()` has always returned the URL and still does for me (on 2.x).
MoritzLost
CC BY-SA 4.0
2023-04-19T21:13:43.887Z
Do you mean Craft 2.x? I'm on 3.x.
4midori
CC BY-SA 4.0
2023-04-20T09:34:40.443Z
@midori I mean 2.x of the plugin – that's the branch for Craft 4, 1.x is for Craft 3. Are you seeing the same issue with other typed link fields? In other templates, or even on other sites?
MoritzLost
CC BY-SA 4.0
2023-04-20T22:12:34.693Z
I'm using the 1.x branch for Craft 3. I just installed the plugin on a Craft 4 site, and the syntax has changed there, the plugin works better too.
4midori
CC BY-SA 4.0
2023-04-18T19:24:15.567Z
2023-04-18T19:24:15.567Z
4midori
<p>It's impossible to tell what's going wrong there without additional information. Your code is correct, and it's unlikely that there's a bug causing this basic feature to not work correctly. Try dumping the <code>button</code> field to see if it actually contains a URL:</p>
<pre class="lang-twig prettyprint-override"><code>{% dd item.button %}
</code></pre>
<p>If it doesn't, make sure your field actually contains a URL in the backend – are you maybe looking at a draft in the backend, but at the live version of the entry in the frontend?</p>
<p>If it does, try <code>{% dd item.button.getUrl() %}</code> – if this shows the URL, the issue is probably something else in your template.</p>

CC BY-SA 4.0
2023-04-18T01:11:26.467Z
I edited my Q to reflect dumped values, could you have another look?
4midori
CC BY-SA 4.0
2023-04-18T07:33:47.887Z
@4midori Hm, curious. Based on the dumps and your code, everything should work as expected. Are you able to update to the latest Craft 3.x or 4.x release, just to see if it's a bug that's already been fixed? I still think the most likely issue is something related to the templates. For example, something in your CSS causing the link to be invisible, or maybe you're seeing the cached output of your template? If none of those help, you could open an issue on GitHub for this, maybe it really is a bug in the plugin.
MoritzLost
CC BY-SA 4.0
2023-04-17T07:48:02.700Z
2023-04-17T07:48:02.700Z
MoritzLost
<p>I'm using this plugin/fieldtype</p>
<p><a href="https://github.com/sebastian-lenz/craft-linkfield" rel="nofollow noreferrer">https://github.com/sebastian-lenz/craft-linkfield</a> v1.0.25</p>
<p>on Craft 3.7.61. When I try to output some of its values, for example:</p>
<pre><code>{{ item.button.getUrl() }}
</code></pre>
<p>I get no result. I am able to output:</p>
<pre><code>{{ item.button.getText() }}
</code></pre>
<p>without issue.</p>
<p><strong>Clarification</strong></p>
<p>When I dump a field having an external URL, I get the expect value:</p>
<pre><code>^ typedlinkfield\models\Link {#4461 ▼
+ariaLabel: null
+customQuery: null
+customText: &quot;versa&quot;
+target: &quot;&quot;
+title: &quot;&quot;
+type: &quot;url&quot;
+value: &quot;https://versastudio.com&quot;
-prefetchedElement: null
-linkField: typedlinkfield\fields\LinkField {#4101 ▶}
</code></pre>
<p>When I dump one with a Craft entry, I get the entry ID.</p>
<pre><code>^ typedlinkfield\models\Link {#4352 ▼
 +ariaLabel: null
 +customQuery: null
 +customText: &quot;Hello&quot;
 +target: &quot;&quot;
 +title: &quot;&quot;
 +type: &quot;entry&quot;
 +value: &quot;48328&quot;
 -prefetchedElement: null
 -linkField: typedlinkfield\fields\LinkField {#4118 ▶}
</code></pre>
<p>And I am unsure how to then get the URL for a simple  link.</p>

<field><custom-field><object>
Can't access values in Typed Link Field
# Can't access values in Typed Link Field

(Asked by: username_0 on 2023-04-14)

I'm using this plugin/fieldtype
https://github.com/sebastian-lenz/craft-linkfield v1.0.25
on Craft 3.7.61. When I try to output some of its values, for example:
{{ item.button.getUrl() }}

I get no result. I am able to output:
{{ item.button.getText() }}

without issue.
Clarification
When I dump a field having an external URL, I get the expect value:
^ typedlinkfield\models\Link {#4461 ▼
+ariaLabel: null
+customQuery: null
+customText: "versa"
+target: ""
+title: ""
+type: "url"
+value: "https://versastudio.com"
-prefetchedElement: null
-linkField: typedlinkfield\fields\LinkField {#4101 ▶}

When I dump one with a Craft entry, I get the entry ID.
^ typedlinkfield\models\Link {#4352 ▼
 +ariaLabel: null
 +customQuery: null
 +customText: "Hello"
 +target: ""
 +title: ""
 +type: "entry"
 +value: "48328"
 -prefetchedElement: null
 -linkField: typedlinkfield\fields\LinkField {#4118 ▶}

And I am unsure how to then get the URL for a simple  link.

**Tags:** field, custom-field, object

---

## 2 answers

### Answer by username_0 on 2023-04-18. Score: 1 | Accepted answer

At some unknown point, there was a change in the way this plug-in works. The output of getUrl() only works for certain types of links. If the link is an entry or asset, the ID is returned instead.
So I did this:
          {% switch column.button.type %}
            {% case 'entry' %}
              {% set theUrl = craft.entries().id(column.button.value).one().url() %}
            {% case 'asset' %}
              {% set theUrl = craft.assets().id(column.button.value).one().url() %}
            {% default %}
              {% set theUrl = column.button.getUrl() %}
          {% endswitch %}

> **Comments:**
> **username_1**: I don't think that's the normal behaviour. `getUrl()` has always returned the URL and still does for me (on 2.x).  
> **username_0**: Do you mean Craft 2.x? I'm on 3.x.  
> **username_1**: @midori I mean 2.x of the plugin – that's the branch for Craft 4, 1.x is for Craft 3. Are you seeing the same issue with other typed link fields? In other templates, or even on other sites?  
> **username_0**: I'm using the 1.x branch for Craft 3. I just installed the plugin on a Craft 4 site, and the syntax has changed there, the plugin works better too.  

---

### Answer by username_1 on 2023-04-17. Score: 1

It's impossible to tell what's going wrong there without additional information. Your code is correct, and it's unlikely that there's a bug causing this basic feature to not work correctly. Try dumping the button field to see if it actually contains a URL:
{% dd item.button %}

If it doesn't, make sure your field actually contains a URL in the backend – are you maybe looking at a draft in the backend, but at the live version of the entry in the frontend?
If it does, try {% dd item.button.getUrl() %} – if this shows the URL, the issue is probably something else in your template.

> **Comments:**
> **username_0**: I edited my Q to reflect dumped values, could you have another look?  
> **username_1**: @4midori Hm, curious. Based on the dumps and your code, everything should work as expected. Are you able to update to the latest Craft 3.x or 4.x release, just to see if it's a bug that's already been fixed? I still think the most likely issue is something related to the templates. For example, something in your CSS causing the link to be invisible, or maybe you're seeing the cached output of your template? If none of those help, you could open an issue on GitHub for this, maybe it really is a bug in the plugin.  

---

