Context Parameter

Hello! Im trying to use the context parameter for my Practicum exercise for the developers certification and dont seem to be getting it right on how to use it. Here is how i set it up in my section template and then you can see it been used in my home page template…
Thanks for the help!

Ive already corrected the missing # from one but still not working

Try

background_color= {{context.background_color ||'#ccc'}}

in your dnd_section.
You’ve also got a comma at the end there that might cause issue.

Likewise in your template, I’d remove the comma after “#fff” unless you’re adding more parameters.

Might not be the solution but it’s the first place I’d start.


Barry Grennan

Freelance HubSpot CMS Developer

Website | Contact | LinkedIn

Moderator note: While this solution may not address the original poster’s specific situation, it could be helpful for other community members facing similar challenges.

Hello Barry! Thanks for the answer but its still not working, any more thoughts on what im doing wrong? What else do i need to add up to have a context parameter working? Any extra setup?
Thanks!

Could you post your code? It’ll make it easier to troubleshoot


Barry Grennan

Freelance HubSpot CMS Developer

Website | Contact | LinkedIn

Hi Barry! thanks again for your answer! The section is showing and the path is actually section/section.html because i didnt use the boilerplate, just created it from scratch. Does the sections folder has to be named sections strictlly? If not, dont really know what else to do. Just did exactly what the certificate videos teach briefly about the context parameter. Is there any further documentation? havent find any att all.

Is the section showing? I notice that the path you’re using is “../section/section.html”

If it’s the boilerplate you’re using this folder would be called sections.

When you view the code in Hubspot Developer Tools are there any errors/warnings?


Barry Grennan

Freelance HubSpot CMS Developer

Website | Contact | LinkedIn

Hi Barry! Here is the only code i have to link the context parameter. I have change the section folder to sections, just in case. So the path now is sections/section.html. The section is also displaying properly. Thanks in advance!

Sorry, I meant could you copy and pate your code so I can test it. Both the section code and the template code.


Barry Grennan

Freelance HubSpot CMS Developer

Website | Contact | LinkedIn

Dont worry! Here It is!
Template:

<!--
templateType: page
label: home page
isAvailableForNewContent: true
-->
<!doctype html>
<html>
<head>
<meta charset=“utf-8”>
<title>{{ content.html_title }}</title>
<meta name=“description” content=“{{ content.meta_description }}”>

{{ require_css (get_asset_url(‘../css/main.css’)) }}
{{ require_css (get_asset_url(‘../css/layout.css’)) }}
{{ standard_header_includes }}
</head>
<body>
<div class=“page-wrap”>
{% block header %}
{% global_partial path=“./partials/header.html” %}
{% endblock header %}

{% block body %}
{% dnd_area “dnd_area” %}
{% include_dnd_partial
path=“../sections/section.html”
context={
“background_color”: “#fff”
}
%}
{% end_dnd_area %}
{% endblock body %}

{% module “module_16796047514203” path=“/foodie-theme/modules/foodie-pics”, label=“foodie-pics” %}

{% block footer %}
{% global_partial path=“./partials/footer.html” %}
{% endblock footer %}
</div>
{{ standard_footer_includes }}
</body>
</html>
and Section:

<!--
templateType: section
label: Two- column content
isAvailableForNewContent: true
description: " Section separated in two columns with an image and text in each."
-->

{% dnd_section
background_color= {{context.background_color ||‘#ccc’}}
%}
{% dnd_column
offset=0,
width=6%}
{% end_dnd_column %}

{% dnd_column
offset=6,
width=6%}
{% end_dnd_column %}
{% end_dnd_section %}