Add RDF data inside header.

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
thecas
Registered User
Posts: 55
Joined: Sun Feb 04, 2018 4:25 pm

Add RDF data inside header.

Post by thecas »

Hi.
I want to add this RDF data inside the header.

Code: Select all

<script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "WebSite",
        "name": "Wisp Forum",
        "url": "https://wisp-forum.it",
        "sameAs": [
                   "https://www.facebook.com/wispforum/"
                   
                   ],
                   "potentialAction": {
                       "@type": "SearchAction",
                       "target": "https://www.wisp-forum.it/search.php?keywords={search_term_string}",
                       "query-input": "required name=search_term_string"
                   }
    }
</script>
I properly modify my template,but, at the moment, phpbb see {search_term_string} as an internal variable (an that's not correct).
I want to print exactly the string {search_term_string} without modify. How I can fix it?

If this code will work properly one user will search inside my forum directly from google. (wow!)
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 4259
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: Add RDF data inside header.

Post by thecoalman »

A quick suggestion. You'll need to test it, at the very least it will set you off in the right direction.

Open includes/functions.php around line 4345 you'll find a giant array of common variables used in templates. First part of it:

Code: Select all

		'SITENAME'						=> $config['sitename'],
		'SITE_DESCRIPTION'				=> $config['site_desc'],
		'PAGE_TITLE'					=> $page_title,
Add to the array:

Code: Select all

'SEARCH_TERM_STRING'						=> '{search_term_string}',

In the template change {search_term_string} to {SEARCH_TERM_STRING}
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
mrgoldy
Development Team Member
Development Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: Add RDF data inside header.

Post by mrgoldy »

The { is a delimiter in the TWIG syntax, the template syntax that's used by phpBB.
To post that delimiter to your template you have to escape it.
{{ '{' }}search_term_string{{ '}' }} will print {search_term_string} without parsing it.

So it would look like this:

Code: Select all

<script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "WebSite",
        "name": "Wisp Forum",
        "url": "https://wisp-forum.it",
        "sameAs": [
                   "https://www.facebook.com/wispforum/"
                   
                   ],
                   "potentialAction": {
                       "@type": "SearchAction",
                       "target": "https://www.wisp-forum.it/search.php?keywords={{ '{' }}search_term_string{{ '}' }}",
                       "query-input": "required name=search_term_string"
                   }
    }
</script>
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
thecas
Registered User
Posts: 55
Joined: Sun Feb 04, 2018 4:25 pm

Re: Add RDF data inside header.

Post by thecas »

Thank you very much. With the second type of modify it works. The first one doesn't!
This topic can be closed!
Post Reply

Return to “phpBB Custom Coding”