Keyword

[SOLVED] Trying to retrieve extraFields unsuccessfully

  • Peter Lærke
  • Peter Lærke's Avatar Topic Author
  • Offline
  • New Member
More
11 years 1 week ago #118639 by Peter Lærke
Hello everyone,

I have now been trying for a couple of days to get this seemingly simple syntax to work for me:
Log in  or Create an account to join the conversation.

  • Yiota
  • Yiota's Avatar
  • Visitor
11 years 1 week ago #118640 by Yiota
What type is your extrafield? If it is link then you cannot put it inside another link since it generates the whole <a> element and your output would be

<a href="<a href="<?php echo $this->item->extraFields->external_url->value; ?>".

You can change it to textfield if you want to be able to generate the link through your php file.

Please Log in or Create an account to join the conversation.

  • Peter Lærke
  • Peter Lærke's Avatar Topic Author
  • Offline
  • New Member
More
11 years 1 week ago #118641 by Peter Lærke
Replied by Peter Lærke on topic Re: Trying to retrieve extraFields unsuccessfully
Thank you for your reply!

The field type was 'link' and I've now changed it to text field per your suggestion.

However, it's still not working. It just links to the root url of the site and the whole expression/line of php code just outputs a "/" when I go to 'Inspect element' in the browser.

Is the path to the extra field faulty?

Please Log in or Create an account to join the conversation.

  • Yiota
  • Yiota's Avatar
  • Visitor
11 years 1 week ago #118642 by Yiota
Is it possible for you to provide the code snippet of the whole block you are trying to modify from your file?
Also double check that the alias of the extrafield is correct.

Please Log in or Create an account to join the conversation.

  • Peter Lærke
  • Peter Lærke's Avatar Topic Author
  • Offline
  • New Member
More
11 years 1 week ago - 11 years 1 week ago #118643 by Peter Lærke
Replied by Peter Lærke on topic Re: Trying to retrieve extraFields unsuccessfully
<!-- Item Image -->
<?php if($this->item->params->get('catItemImage') && !empty($this->item->image)): ?>
<div class="catItemImageBlock">
   <span class="catItemImage">
      <a href="<?php echo $this->item->extraFields->external_url->value; ?>" title="<?php if(!empty($this->item->image_caption)) echo K2HelperUtilities::cleanHtml($this->item->image_caption); else echo K2HelperUtilities::cleanHtml($this->item->title); ?>">
          <img src="<?php echo $this->item->image; ?>" alt="<?php if(!empty($this->item->image_caption)) echo K2HelperUtilities::cleanHtml($this->item->image_caption); else echo K2HelperUtilities::cleanHtml($this->item->title); ?>" style="width:<?php echo $this->item->imageWidth; ?>px; height:auto;" />
      </a>
    </span>
<div class="clr"></div>
</div>
<?php endif; ?>

I tried changing the alias to "url" to make sure it wasn't a typo or something.

Also, I'm wondering if the 'extra field group' has any part to play in this?

EDIT: Wow, code gets really messy to look at.. Hope you can read it.
2. EDIT: Cleaned it up just a bit.

Please Log in or Create an account to join the conversation.

  • Yiota
  • Yiota's Avatar
  • Visitor
11 years 1 week ago #118644 by Yiota
Have you Enabled the parameter for the extra fields to Show in the category listing?

Please Log in or Create an account to join the conversation.

  • Peter Lærke
  • Peter Lærke's Avatar Topic Author
  • Offline
  • New Member
More
11 years 1 week ago #118645 by Peter Lærke
Replied by Peter Lærke on topic Re: Trying to retrieve extraFields unsuccessfully
Nope, that was the problem apparently. Thanks for suggesting that.

I had it set to hide the extra field because I didn't want it to actually show on the page, just be there to supply the link for the image.

So now I just need to disable whatever code is displaying the extra field and I'm good to go.

Thank you for your help!

Please Log in or Create an account to join the conversation.