Access request's URL parameters in stencil - bigcommerce

Can I access the request’s query params in stencil?
So if you go to http://example.com/?name=Bob
Can I render something like:
Hello {{url.name}}!
It has to be server-side rendered, not browser JavaScript.
Why? Well, I actually want to share the results of a quiz on Facebook, so the og:image tag needs to point at a picture of the score. So I share a link like http://example.com/quiz/?quizScore=encodedscoreresult and the page then contains:
<meta property="og:image"
content="https://myapi.example.com/quizresultsimage?quizScore=encodedscoreresult" />

Not a full solution, as you can't access an individual parameter's value, but...
The settings.facebook_like_button.href does contain the request URL, URL encoded as https%3A%2F%2Fexample.com%2Fquiz%3FquizScore%3Dencodedscoreresult
You can extract the whole query string from the URL using:
<meta property="og:image"
content="https://myapi.example.com/quizresultsimage{{get "search" (getObject "search" (urlParse (decodeURI settings.facebook_like_button.href)))}}" />
However, that will include all the query parameters, so that may be a security risk passing extra parameters from your stencil site to the api that aren't desired.
Simpler (and perhaps safer), you can pass the whole URL as a parameter in the meta tag, and then the API will have to decode it:
<meta property="og:image"
content="https://myapi.example.com/quizresultsimage?url={{settings.facebook_like_button.href}}" />
which results in:
<meta property="og:image"
content="https://myapi.example.com/quizresultsimage?url=https%3A%2F%2Fexample.com%2Fquiz%3FquizScore%3Dencodedscoreresult" />
Because there is only one parameter in the query string, you can be sure you're not passing anything undesired to the target URL.
If you just need the decoded URL you can use:
{{assignVar "requestUrl" (decodeURI settings.facebook_like_button.href) }}
{{getVar "requestUrl"}}

Related

Is there a way to declare undefined or empty property value with Schema Microdata?

I'm building structured data for basics website and I often have missing mandatory property.
Is there a syntax to pass "undefined" or empty as a valid property with Microdata syntax ?
Exemple, i have an old blog article and I have no date linked, so i would put :
<meta itemprop="datePublished" content="">
<meta itemprop="dateModified" content="">
But this is invalid for Schema debug app :
Is there a specific way to tell "I dont't have this information, that's not an error" with Microdata ?

Can I separate tags with comma in HTL Slightly?

My problem is: I have to customize properties of a meta tag on AEM Console.
I have this meta tag:
<meta name="tags" data-sly-test="${properties.tag}" content="${properties.tag}" />
If an utent add more attributes on AEM console, I need that these attributes are separeted by ';'.
The output should be:
<meta name="tags" content="hello;world;laptop;screen"/>
You can use the join option (https://github.com/adobe/htl-spec/blob/master/SPECIFICATION.md#124-array-join):
content="${properties.tag # join=';'}"

Where i wants to give the actual keyword in my website for SEO?

I have 10 keywords for my website. Please tell Where i wants to give the actual keyword in my website (home page or any place?)for display google search?
For put keywords in Home Page or any other Page:
Login to Admin panel.
go to CMS->Pages than select any page.
Here in Mete Data tab you can insert your Meta Keywords and Meta Description.
For put keyword in Category page:
go to Catalog->Manage Categories than select any category.
Here you can insert your Meta Keywords and Meta Description.
For put keyword in Product Detail page:
goto Catalog->Manage Products than select any product.
Here in Meta Information tab insert your Meta Title,Meta Keywords and Meta Description.
(If not display Meta Information tab or meta attributes than goto Catalog->Attributes->Manage Attributes Set to manage meta attribues for product accoring to product type.)
u should put those in meta tag
<meta name="description" content="Awesome Description Here">
of your page
you should add these meta tags in header of all pages.
<meta name="title" content="TITLE of Page">
<meta name="description" content="Description of Page">
<meta name="keywords" content="title,tag,tag2">
avoid repeating the keywords

VBA insertAdjacentHTML , stripping tags

I am processing some HTML in VBA and want to inject a element to the tag.
oElement.insertAdjacentHTML "beforeEnd", "<base>HELLO</base>"
If I inspect the oElement.OuterHTML all that is added is HELLO
...<LINK rel=stylesheet type=text/css href="css/default.css">HELLO</HEAD>...
If I try adding li tags , it works as expected.
oElement.insertAdjacentHTML "beforeEnd", "<li>HELLO</li>"
Result
....<LINK rel=stylesheet type=text/css href="css/default.css">HELLO <LI>HELLO</LI> </HEAD>...
I've tried using just <base /> or <base href="blah blah , nothing get's added. Am I missing some key piece of knowledge about insertAdjacentHTML.
Any ideas??
You need to use IHTMLDOMNode interface for head object (don't know why, but it works). Create a "BASE" element, set attribute for href and finally add it to a head using appendChild.

<fb:comments> is displaying different layouts according to the href used inside. Why?

I'm trying to understand why two different layouts are displayed by the placeholder, according to the href parameter used inside of it. Quick example - say I'm using http://example.com/ as the href resource - I'll get the usual header before the comments, with the number of comments on the left and "Add a comment" on the right. However, when I'm changing the href to the one I really need (i.e. the page where the box resides), I only get a list of comments, no number of comments, no "add a comment". Have a look at this to see what I mean: http://popz.ro/comments.php?aid=1
Why, oh why? (something to do with the app I've registered?)
Thanks!
When I go to your link, I see a comments area as well as an input box to add new comments.
This appears to be correct based upon the plugin code used:
<fb:comments width="950" href="http://popz.ro/comments.php?aid=1"></fb:comments>
I also see you've got the og meta tags specificed too, which will help:
<meta property="og:title" content="Popz" />
<meta property="og:type" content="website" />
<meta property="og:url" content="http://popz.ro/comments.php?aid=1" />
<meta property="og:image" content="http://popz.ro/png/fpopz.png" />
<meta property="og:site_name" content="Popz | fresh de stiri" />
<meta property="fb:admins" content="584603173" />
<meta property="fb:app_id" content="277079292362391" />
Also the app_id matches between the FB.init() code as well as that specified in the meta tags. So there's no problem there.
I see only 2 comments, and the default is 2, so it's not going to show the # of comments until you go over that amount.