liquid Shopify - how to access the current URL - url

I need to access the URL when in the cart as there is an issue with the locale that I need to fix. I tried
{{ shop.secure_url }} and {{ page.url. }}
and many more but couldn't access it. Any idea?
thanks but still not working. I can't access the full URL in mini-cart.liquid .
I used this conditional statement:
{% if request.locale.iso_code == "de" and request.origin contains 'https://myshop.ch' %} href="/{{ request.locale.iso_code }}/checkout"

Check the request object: https://shopify.dev/api/liquid/objects?shpxid=ae783aed-8802-4157-ED00-1067D234E633#request it should contain everything you need.
{
"design_mode": false,
"host": "polinas-potent-potions.myshopify.com",
"locale": {},
"origin": "https://polinas-potent-potions.myshopify.com",
"page_type": "index",
"path": "/"
}
``

Related

Using an API with Zapier but getting "The app returned ""rest_data" param is incorrect. JSON data expected"."

So i grab data from an Airtable and then have a custom PUT as the second action using Samba Lives API, specifically Sessions -> PUT Session https://documenter.getpostman.com/view/2014682/samba-live-rest-api/6YzutHM#c87c1db7-2b5c-9b2b-7d63-6b531793cfe2
This is the data in the custom PUT:
Method: PUT
URL: https://samba.live/api/2/ourusername/session
Data Pass-Through? No
Data:
input_type=json&rest_data={
"topic": "Crazy Topic",
"duration": 30,
"start_time": "2025-09-10 12:00:00",
"invited_participants":[
{
"email":"flast#company.com",
"first_name":"First",
"last_name":"Last",
"role":2,
"send_email_invitation":true
},
{
"email": "first.last#gmail.com",
"first_name": "First",
"last_name": "Last",
"role": 1,
"send_email_invitation": true
}
],
}
Unflatten- yes
Basic Auth- ourusername|ourpassword
Headers- none
But the test fails and says "App returned "rest_data" param is incorrect. JSON is expected."
I'm not really sure what to try and Zapier just said we don't help with that. Only thing i could think to try was to delete the input_type section, and that returned with an error saying "Topic is required." Same thing when i left most of it and just deleted the rest_data part.
Any ideas?
Fixed - apparently the comma after the ] threw everything off.

Slack message "link button" not showing when URL contains underscore

I searched high and low but couldn't find a solution for this...
I'm designing a basic slack message with link buttons and found that the button will not show in the message when the host contains an 'underscore'...
You can try below example here: https://api.slack.com/docs/messages/builder
{
"text": "some text here...",
"attachments": [
{
"title": "TITLE",
"actions": [
{
"type": "button",
"text": "Link button",
"url": "https://www.some-site.com"
}
]
}
]
}
When you change www.some-site.com to www.some_site.com, the button disappears ...
Any suggestions on how to format the url so that the button shows up? According to the documentation, only the &, < and > characters need to be escaped, correct? I also tried encoding the URL, that didn't help either ... help?
This is a valid response from Slack, since www.some_site.com is not a valid URL.
You can not use underscores in hostnames, where hostname in your example is some-site. You can however use underscores in the label of a URL, so e.g. www_super.some-site.com should work.
Sources:
- https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
- http://domainkeys.sourceforge.net/underscore.html

Twilio liquid loop through parsed json data

I am using Twilio IVR studio. I am using http request widget and know I can call 'widgets.MY_WIDGET_NAME.parsed.[parsed variable name]' to get the returned json data.
Say like I have the above widget return 7 jobs inside the array of hashes. I just want to return the job_id for each one and not the other data inside it. How would I got about doing that with liquid? I know there is loop but having a hard time getting.
I can do something like widgets.MY_WIDGET_NAME.parsed.[parsed variable name][0].job_id and it returns the first id. Any help would be appreciated.
"parsed": {
"success": "7 visits found",
"visits": [
{
"job_id": "12344",
"check_in": "",
"check_out": ""
},
{
"job_id": "12344",
"check_in": "",
"check_out": ""
},
{
"job_id": "12344",
"check_in": "",
"check_out": ""
},
{
Twilio developer evangelist here.
Twilio Studio supports Liquid templates. You can iterate a number of ways in Liquid including using a for loop. So you could do something like:
{% for job in widgets.MY_WIDGET_NAME.parsed.[parsed variable name] %}
{{ job.job_id }}
{% endfor %}
Let me know if that helps.
this note might help: Parse JSON into array javascript with Twilio Function
if not, this might: https://www.twilio.com/docs/studio/widget-library/run-function (under the Response heading, it's the description for Content Type)
details: i asked the same question of the NickH at Twilio and got this gem back that i have permission to share: "(Twilio) automatically parses JSON payloads returned to Function widgets and HTTP Request widgets! However, it has to be a JSON object, not an array. (don't worry, it can still contain an array). Instead of this:
[
{},
{},
{}
]
try returning this:
{
"result":[
{},
{},
{}
]
}
You'll access these variables as {{widgets.NAME_OF_FUNCTION_WIDGET.parsed.result[index]}}​(index being an integer starting from 0, for this example, 0, 1, and 2)."
hth!

With Rails 4 and structured logging, how can I add the request id field to logs?

I am adding structured logging to a Rails 4 app. Using lograge and logstash-logger as describe in this article, I've got things mostly working.
I'm having trouble adding request id to the logs. The closest I've found is to add this to config/${ENV}.rb:
config.log_tags = [:uuid]
But this adds the request id to the tags list, instead of adding it as a named field.
{
"tags": [
"da76b4be-01ae-4cc4-8d3c-87062ea02cfe"
],
"host": "services",
"severity": "DEBUG",
"#version": "1",
"#timestamp": "2016-09-13T17:24:34.883+00:00",
"message": "..."
}
This is problematic. It makes it more awkward and less obvious on how to search for a particular request id. Plus, parsing the message in logstash it overwrites any other tags that are already associated with the log message.
Is there any way that I can add the request id to the log as a named field?
{
"request_id", "da76b4be-01ae-4cc4-8d3c-87062ea02cfe",
"host": "services",
"severity": "DEBUG",
"#version": "1",
"#timestamp": "2016-09-13T17:24:34.883+00:00",
"message": "..."
}
Old question but maybe it will help someone like me who struggled to find a simple way to do this.
Using the custom_payload (instead of custom_options), you can directly access the request received by the controller and get its id to add it to the logs:
config.lograge.custom_payload do |controller|
{
request_id: controller.request.request_id
}
end
No need to configure the log_tags for this to work.
There are several ways to do this. From Lograge, you can use the custom_options:
# all your lograge stuff...
config.lograge.enabled = true
config.lograge.custom_options = lambda do |event|
# use the `event.payload`
{uuid: event.payload[:uuid]}
end
You can overload any option in here - they'll take over the lib's ones.
The code responsible for this is here. The test that shows it work is here.

Mandrill ignores line breaks (\n)

Using the send-template method and the Lutung Mandrill Java API implementation, when a template variable contains line breaks of the form \n, they are totally ignored or stripped on generated emails. The Strings containing \n characters are kept untouched untill the GET send-template method is executed. So I guess there is some String analysis and conversion on Mandrill servers which removes special characters.
How can I make work again line breaks on Mandrill emails?
In my case I am using Handlebars for mandrill templates and I have solved this by sending HTML to the template <br/> instead of \n by replacing \n in my string with <br/> something like: .Description.Replace("\n", "<br/>");
And then on the mandrill template I put the variable inside {{{ variable }}} instead of {{ variable }}
http://blog.mandrill.com/handlebars-for-templates-and-dynamic-content.html
HTML escaping
Handlebars HTML-escapes values returned by an
{{expression}}. If you don't want Handlebars to escape a value, use
the "triple-stash", "{{{.
In your template:
<div> {{{html_tag_content}}} </div> In your API request:
"global_merge_vars": [ {
"name": "html_tag_content",
"content": "This example<br>is all about<br>the magical world of handlebars" } ]
The result:
This example
is all about
the magical world of handlebars
If you want to send more complex content, be it html, or variables with break lines and whatnot, you can first render the template and then send the message, instead of directly using send-template.
Render the template with a call to templates.render:
{
"key": "example key",
"template_name": "Example Template",
"template_content": [
{
"name": "editable",
"content": "<div>content to inject *|MERGE1|*</div>"
}
],
"merge_vars": [
{
"name": "merge1",
"content": "merge1 content\n contains line breaks"
}
]
}
Save the result to a variable rendered_content.
Send the message using the rendered template with messages.send:
{
"message": {
"html": rendered_content,
...
...
}

Resources