Custom Metadata in News articles
Custom Metadata in News articles
I would like to add some Page Specific Metadata into News articles but there is no "Logic" tab on the News module like there is for Pages.
Can this be done?
Can this be done?
Re: Custom Metadata in News articles
In your page template add something like
In your news template add
Code: Select all
{if $metadata}{$metadata}{/if}
Code: Select all
{$metadata="your metadata tag here" scope=global}
Not getting the answer you need? CMSMS support options
Re: Custom Metadata in News articles
You can create custom field(s) and use them to fill in the metadata. This tutorial will be a good start:
https://cmscanbesimple.org/blog/base-cm ... d-metatags
https://cmscanbesimple.org/blog/base-cm ... d-metatags
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Re: Custom Metadata in News articles
Thanks. Specifically I want to set an an og:image image for each News article. I see you cover this with these two lines:
The issue is that you have specified a static "page_image.png" whereas I need a different image for each News article. Where would I enter this data within the News article admin area?
Code: Select all
{$page_image = $page_image|default:"{$theme_url}/page_image.png" scope=global}
Code: Select all
<meta property="og:image" content="{$page_image}">
Re: Custom Metadata in News articles
Make an image field for news articles, then test for it and assign it to $page_image in your news template, being sure to set the scope to global.
Not getting the answer you need? CMSMS support options
Re: Custom Metadata in News articles
How do I create a custom input field for the news module?
Edit: Ignore me, I found it! Thanks.
Edit: Ignore me, I found it! Thanks.
Re: Custom Metadata in News articles
One final thing, when metadata is set in the news article, I do not want the page specific metadata output, otherwise I will get two og:image lines output.
Can I supress the page specific metadata in this case, whilst still outputting the global metadata?
Can I supress the page specific metadata in this case, whilst still outputting the global metadata?
Re: Custom Metadata in News articles
yep, anything in a template can be wrapped in {if} statements. {if !$my_custom_metadata]{metadata}{/if}
This can end up being a bit tricky as {metadata} includes global metadata as well as page-specific, so you want to plan ahead how you do this. Personally I create fields for all metadata in my page template, so the page-specific metadata field should only be used on the very rare occasion you need to add something unique to the page. I wouldn't actually put og tags or titles in there. That way you can test for each field in your page template, or set defaults like: <meta property="og:image" content="{$customogimage|default:$ogimage|default:$defaultogimage}">
In the above example $ogimage would be a field in your page template, $customogimage could be set in modules like News, and then $defaultogimage defined as something to use if neither of those are set.
There's lots of different ways to do it all, this is just one example to get the gears turning.
This can end up being a bit tricky as {metadata} includes global metadata as well as page-specific, so you want to plan ahead how you do this. Personally I create fields for all metadata in my page template, so the page-specific metadata field should only be used on the very rare occasion you need to add something unique to the page. I wouldn't actually put og tags or titles in there. That way you can test for each field in your page template, or set defaults like: <meta property="og:image" content="{$customogimage|default:$ogimage|default:$defaultogimage}">
In the above example $ogimage would be a field in your page template, $customogimage could be set in modules like News, and then $defaultogimage defined as something to use if neither of those are set.
There's lots of different ways to do it all, this is just one example to get the gears turning.
Not getting the answer you need? CMSMS support options
Re: Custom Metadata in News articles
I may have to supress {metadata} altogether then and duplicate the global metadata in the news module, since a significant number of og:image entries have already been made in the page-specific metadata sections.
In any case, very helpful, thanks.
In any case, very helpful, thanks.
Re: Custom Metadata in News articles
I came up with this to replace page og:image with news og:image. I'm sure it could be much better coded but it works!
Code: Select all
{if !empty($entry->fields.Page_Specific_Metadata->value)}
{capture name=metadata assign=metadata}
{metadata}
{/capture}
{capture name=metadata assign=metadata}
{$metadata|regex_replace:"/<meta property=\"og:image\" content=\".*?\" \/>/":""}
{/capture}
{$new_meta = $entry->fields.Page_Specific_Metadata->value}
{$metadata = "`$metadata`$new_meta" scope=global}
{/if}