CMS Development

LSeth
Member | Platinum Partner
Member | Platinum Partner

Data from a custom field to module

SOLVE

I am setting up a module using the page custom field. On a page template I have a custom image field. When the module selects a page I want to bring the custom field from that page and display it when the module is used. In the code below its the data in the <img> tag that is not working. The image custom field is named portfolio_logo_upload. What am I missing? Thanks.

 

 

{% set our_work_content = content_by_id(module.page_selection) %}
<div class="portfolio-selection-single" style="background-image: url({{our_work_content.featured_image}})">
<a href="{{ our_work_content.absolute_url }}"></a>
<img src="{{widget_data.portfolio_logo_upload.img.src}}">
</div>

0 Upvotes
1 Accepted solution
LSeth
Solution
Member | Platinum Partner
Member | Platinum Partner

Data from a custom field to module

SOLVE

@webdew @albertsg Thanks for the input. I have figured out the Hubl needed to bring in a custom field. I went into the developers info of the page where the logo is uploaded via a custom field to see the json and arrived at a solution. Here is my solution:

 

{{our_work_content.widgets.portfolio_logo_upload.body.src}}

View solution in original post

4 Replies 4
LSeth
Solution
Member | Platinum Partner
Member | Platinum Partner

Data from a custom field to module

SOLVE

@webdew @albertsg Thanks for the input. I have figured out the Hubl needed to bring in a custom field. I went into the developers info of the page where the logo is uploaded via a custom field to see the json and arrived at a solution. Here is my solution:

 

{{our_work_content.widgets.portfolio_logo_upload.body.src}}

albertsg
Guide

Data from a custom field to module

SOLVE

Hello @LSeth, if I don't get it wrong you want to use the image from the image module in a page which has been selected in a page module, right? 

 

I've recently done something similar and the key to find the solution is understanding what the page module returns.

 

If you have only 1 page, it will return a string with the ID of the page. With this string you can use the function content_by_id to return the page/blog object.

 

Once you have the object, you just need to access the module's value. Here's an example that works:

 

{# First, get the content using the ID returned by the module #}
{% set my_content = content_by_id(module.page_field) %}
{# Then access the page module's information, in this case the src attibute of the image module #}
{{my_content.widgets.module_164444398815712.body.image_field.src}}

 

Just replace module_164444398815712 by the name of your image module.

 

Let me know if you have any questions 🙂

Did my answer help you? Mark it as a solution
LSeth
Member | Platinum Partner
Member | Platinum Partner

Data from a custom field to module

SOLVE

Thanks for the response but I am not using a module for the image on the page template. I don't have the option of copy value or snippet. I am using the following hubl in the page template:

 

{% image "portfolio_logo_upload" label="Upload a Logo" export_to_template_context=true %}

0 Upvotes
webdew
Guide | Platinum Partner
Guide | Platinum Partner

Data from a custom field to module

SOLVE

Hi @LSeth ,

I think you are using "Copy value only" instead of "Copy snippet"

Please try click on "Copy snippet" and replace with your code "<img src="{{widget_data.portfolio_logo_upload.img.src}}">"

Hope this helps!
If we were able to answer your query, kindly help the community by marking it as a solution.
Thanks and Regards.

0 Upvotes