Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom template throwing errors #81

Closed
freder opened this issue Sep 6, 2023 · 7 comments
Closed

Custom template throwing errors #81

freder opened this issue Sep 6, 2023 · 7 comments
Assignees

Comments

@freder
Copy link

freder commented Sep 6, 2023

Replacing {% hook 'seo-fields' %} with {% include 'seo.twig' %} (copied https://github.com/studioespresso/craft-seo-fields/blob/master/src/templates/_meta.twig) throws errors:

image

I assume I'm not doing it right... but I might need a hint as to what's going wrong here.
Maybe add some more details in the documentation?

@janhenckens
Copy link
Member

Hey @freder, could you shared the full template you are using? Thanks!

@freder
Copy link
Author

freder commented Sep 12, 2023

{# SEO Fields meta fields start #}
{% set seoFields = getSeoFields() %}
{% set meta = seoFields.meta %}

{% if meta %}
	{# <title>{{ meta.getPageTitle(element) }}</title> #}
	<meta name="description" content="{{ meta.getMetaDescription() }}">
	{# Facebook #}
	<meta property="og:url" content="{{ craft.app.request.absoluteUrl }}"/>
	<meta property="og:type" content="website"/>
	<meta property="og:title" content="{{ meta.getOgTitle(element) }}"/>
	{% set ogImage = meta.getOgImage() %}
	{% if ogImage %}
		<meta property="og:image" content="{{ ogImage.url }}"/>
		<meta property="og:image:width" content="{{ ogImage.width }}"/>
		<meta property="og:image:height" content="{{ ogImage.height }}"/>
		<meta property="og:image:alt" content="{{ ogImage.alt }}"/>
	{% endif %}
	<meta property="og:description" content="{{ meta.getOgDescription() }}"/>
	<meta property="og:site_name" content=""/>
	<meta property="og:locale" content="{{ currentSite.language }}"/>
	{# Twitter #}
	<meta name="twitter:card" content="summary_large_image" />
	<meta name="twitter:site" content="" />
	<meta name="twitter:url" content="{{ craft.app.request.absoluteUrl }}" />
	<meta name="twitter:title" content="{{ meta.getTwitterTitle(element) }}" />
	<meta name="twitter:description" content="{{ meta.getTwitterDescription() }}" />
	{% if ogImage %}
		<meta name="twitter:image" content="{{ meta.getTwitterImage().url ?? ogImage.url }}" />
	{% endif %}

	{% if craft.app.response.statusCode < 400 %}
		<link rel="canonical" href="{{ meta.getCanonical() }}" />
	{% endif %}
	{% for alt in meta.getAlternate(element) %}
		<link rel="alternate" hreflang="{{ alt.language }}" href="{{ alt.url }}" />
	{% endfor %}
{% endif %}
{# SEO Fields meta fields end #}

@chadcrowell
Copy link

I don't think it is just custom templates. I get the same error when pasting the custom meta commands into a normal entry template:

{% do entry.seo.setMetaTitle('New title') %}
{% do entry.seo.setMetaDescription('custom meta description') %}
{% do entry.seo.setFacebookTitle('Facebook title') %}
{% do entry.seo.setFacebookDescription('custom description') %}
{% do entry.seo.setTwitterTitle('Twitter title') %}
{% do entry.seo.setTwitterDescription('Just for twitter') %}

yields

Impossible to invoke a method ("setMetaTitle") on a null variable.

entire code:

{% extends "_wrappers/main" %}

{% set banner = siteSettings.jobsBanner.one() ?? siteSettings.fallbackBanner ?? null %}

{% set pdfen = entry.pdfEn.one() ?? null %}
{% set pdfes = entry.pdfEs.one() ?? null %}

{% do entry.seo.setMetaTitle('New title') %}
{% do entry.seo.setMetaDescription('custom meta description') %}
{% do entry.seo.setFacebookTitle('Facebook title') %}
{% do entry.seo.setFacebookDescription('custom description') %}
{% do entry.seo.setTwitterTitle('Twitter title') %}
{% do entry.seo.setTwitterDescription('Just for twitter') %}

@freder
Copy link
Author

freder commented Sep 18, 2023

@janhenckens could you please look into this?
my client paid for the plugin and expects this to work.

@janhenckens
Copy link
Member

@freder I'm working on a fix for this, while also trying to fix the errors @chadcrowell reported above. I'll split them in separate releases and move the others to a new issue as they are not related.

Update should be out in a couple of hours.

janhenckens added a commit that referenced this issue Sep 18, 2023
janhenckens added a commit that referenced this issue Sep 18, 2023
@janhenckens
Copy link
Member

@freder can you update to 3.3.3 and see if that fixes the error? You'll also want to update your template to match this one https://github.com/studioespresso/craft-seo-fields/blob/develop/src/templates/_meta.twig

@freder
Copy link
Author

freder commented Sep 19, 2023

seems to work now. thanks

@freder freder closed this as completed Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants