Difference between revisions of "Liquid Template Variables - request"

From Spiffy Stores Knowledge Base

 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
The Liquid template variable '''request''' has the following attributes:
 
The Liquid template variable '''request''' has the following attributes:
 
 
== <code>request.''parameter''</code> ==
 
== <code>request.''parameter''</code> ==
 
 
You can access any request parameter by name.
 
You can access any request parameter by name.
  
Line 12: Line 10:
  
 
<pre>request.theme</pre>
 
<pre>request.theme</pre>
 
 
== <code>request.host</code> ==
 
== <code>request.host</code> ==
 
 
Returns the host name portion of the URL request.
 
Returns the host name portion of the URL request.
  
Line 20: Line 16:
  
 
<pre>storedemo.spiffystores.com</pre>
 
<pre>storedemo.spiffystores.com</pre>
 
 
== <code>request.url</code> ==
 
== <code>request.url</code> ==
 
 
Returns the complete URL used for this request.
 
Returns the complete URL used for this request.
  
Line 28: Line 22:
  
 
<pre>http://storedemo.spiffystores.com/products/widget</pre>
 
<pre>http://storedemo.spiffystores.com/products/widget</pre>
 
 
== <code>request.referer</code> ==
 
== <code>request.referer</code> ==
 
 
Returns the referer URL for this request.
 
Returns the referer URL for this request.
  
For example, if we came to the current page from <nowiki>http://storedemo.spiffystores.com/collections/widgets</nowiki>, then the request.referer returns:
+
For example, if we came to the current page from ''<nowiki>http://storedemo.spiffystores.com/collections/widgets</nowiki>'', then the '''request.referer''' returns:
  
 
<pre>http://storedemo.spiffystores.com/collections/widgets</pre>
 
<pre>http://storedemo.spiffystores.com/collections/widgets</pre>
 
 
== <code>request.remote_ip</code> ==
 
== <code>request.remote_ip</code> ==
 
 
Returns the IP address of the user accessing the page.
 
Returns the IP address of the user accessing the page.
 
 
== <code>request.country</code> ==
 
== <code>request.country</code> ==
 
 
Returns the Country name of the user accessing the page. This information is determined from the IP address, and may not be accurate in all cases. Typically, the results are 99.5% accurate.
 
Returns the Country name of the user accessing the page. This information is determined from the IP address, and may not be accurate in all cases. Typically, the results are 99.5% accurate.
  
Line 50: Line 38:
 
Australia
 
Australia
 
</pre>
 
</pre>
 
 
== <code>request.country_code</code> ==
 
== <code>request.country_code</code> ==
 
 
Returns the two character ISO Country Code of the user accessing the page. This information is determined from the IP address, and may not be accurate in all cases. Typically, the results are 99.5% accurate.
 
Returns the two character ISO Country Code of the user accessing the page. This information is determined from the IP address, and may not be accurate in all cases. Typically, the results are 99.5% accurate.
  
Line 60: Line 46:
 
AU
 
AU
 
</pre>
 
</pre>
 +
== <code>request.province</code> ==
 +
Returns the Province/State name of the user accessing the page. This information is determined from the IP address, and may not be accurate in all cases. Typically, the results are 99.5% accurate.
 +
 +
The name returned is the ISO Printable name. For example:
 +
 +
<pre>
 +
New South Wales
 +
</pre>
 +
== <code>request.province_code</code> ==
 +
Returns the two character ISO Province/State Code of the user accessing the page. This information is determined from the IP address, and may not be accurate in all cases. Typically, the results are 99.5% accurate.
 +
 +
The code returned is the ISO Code. For example:
  
 +
<pre>
 +
NSW
 +
</pre>
 
== <code>request.city</code> ==
 
== <code>request.city</code> ==
 
 
Returns the City name of the user accessing the page. This information is determined from the IP address, and may not be accurate in all cases. Typically, the results are 79% accurate. For example:
 
Returns the City name of the user accessing the page. This information is determined from the IP address, and may not be accurate in all cases. Typically, the results are 79% accurate. For example:
  
Line 68: Line 68:
 
Sydney
 
Sydney
 
</pre>
 
</pre>
 
 
== <code>request.timezone</code> ==
 
== <code>request.timezone</code> ==
 
 
Returns the Time Zone of the user accessing the page. This information is determined from the IP address, and may not be accurate in all cases. For example, if the user is using a proxy, then the time zone of the proxy server will be returned, rather than that of the user.
 
Returns the Time Zone of the user accessing the page. This information is determined from the IP address, and may not be accurate in all cases. For example, if the user is using a proxy, then the time zone of the proxy server will be returned, rather than that of the user.
  
Line 78: Line 76:
 
Australia/Sydney
 
Australia/Sydney
 
</pre>
 
</pre>
 
 
== <code>request.utc_offset</code> ==
 
== <code>request.utc_offset</code> ==
 
 
JavaScript code is inserted in every page to detect the UTC offset on a user's computer. This value, in seconds, is set as a cookie, which can be retrieved and returned here.
 
JavaScript code is inserted in every page to detect the UTC offset on a user's computer. This value, in seconds, is set as a cookie, which can be retrieved and returned here.
  
This value gives an accurate reading of the user's time zone and will probably be more accurate than ''request.timezone''.
+
This value gives an accurate reading of the user's time zone and will probably be more accurate than '''request.timezone'''.
  
 
No value is available when the initial page is displayed, as the JavaScript to calculate the time zone offset has not had a chance to run.
 
No value is available when the initial page is displayed, as the JavaScript to calculate the time zone offset has not had a chance to run.
 
 
== <code>request.client_time</code> ==
 
== <code>request.client_time</code> ==
 
+
Returns the best available guess for the current time on the user's computer. If the '''request.utc_offset''' value is available, then this is used to calculate the time zone. If this value is not available, then the time zone that has been derived from the IP address is used, and failing that, the local time for the store is used.
Returns the best available guess for the current time on the user's computer. If the ''request.utc_offset'' value is available, then this is used to calculate the time zone. If this value is not available, then the time zone that has been derived from the IP address is used, and failing that, the local time for the store is used.
 
 
 
 
== <code>request.currency</code> ==
 
== <code>request.currency</code> ==
 
 
Returns the local currency of the user, based upon the Country from which the client has accessed the page. This information is determined from the IP address, and may not be accurate in all cases.
 
Returns the local currency of the user, based upon the Country from which the client has accessed the page. This information is determined from the IP address, and may not be accurate in all cases.
  
Line 98: Line 90:
 
AUD
 
AUD
 
</pre>
 
</pre>
 
 
== <code>request.user_agent</code> ==
 
== <code>request.user_agent</code> ==
 
 
Returns the user agent string of the user's browser. Each browser returns a unique user agent string, which provides information about the version and features that the browser provides.
 
Returns the user agent string of the user's browser. Each browser returns a unique user agent string, which provides information about the version and features that the browser provides.
  
Line 106: Line 96:
 
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0  
 
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0  
 
</pre>
 
</pre>
 
 
== <code>request.browser</code> ==
 
== <code>request.browser</code> ==
 
 
Returns the name of the user's browser.
 
Returns the name of the user's browser.
  
Line 114: Line 102:
 
Firefox
 
Firefox
 
</pre>
 
</pre>
 
 
== <code>request.browser_version</code> ==
 
== <code>request.browser_version</code> ==
 
 
Returns the version of the user's browser.
 
Returns the version of the user's browser.
  
Line 122: Line 108:
 
25.0
 
25.0
 
</pre>
 
</pre>
 
 
== <code>request.browser_platform</code> ==
 
== <code>request.browser_platform</code> ==
 
 
Returns the platform of the user's browser. This will be the generic type of operating system that the user is running, such as Windows or Macintosh.
 
Returns the platform of the user's browser. This will be the generic type of operating system that the user is running, such as Windows or Macintosh.
  
Line 130: Line 114:
 
Windows
 
Windows
 
</pre>
 
</pre>
 
 
== <code>request.browser_os</code> ==
 
== <code>request.browser_os</code> ==
 
 
Returns the operating system that the user's browser is running under.
 
Returns the operating system that the user's browser is running under.
  
Line 138: Line 120:
 
Windows 7
 
Windows 7
 
</pre>
 
</pre>
 
 
== <code>request.mobile?</code> ==
 
== <code>request.mobile?</code> ==
 
 
Returns true if the user's browser is running on a mobile device.
 
Returns true if the user's browser is running on a mobile device.
 +
== <code>request.tablet?</code> ==
 +
Returns true if the user's browser is running on a tablet device.
  
 
== <code>request.bot?</code> ==
 
== <code>request.bot?</code> ==
 
 
Returns true if the request appears to be coming from a robot or web crawler.
 
Returns true if the request appears to be coming from a robot or web crawler.
 +
== <code>request.ajax?</code> ==
 +
Returns true if the request is using Ajax to render part of the page.
 +
== <code>request.locale</code> ==
 +
Returns the shop_locale of the current request.
 +
== <code>request.page_type</code> ==
 +
Returns the type of the current page. These are the different page types:
  
== <code>request.ajax?</code> ==
+
* 404
 +
* article
 +
* blog
 +
* cart
 +
* collection
 +
* list-collections
 +
* customers/account
 +
* customers/activate_account
 +
* customers/addresses
 +
* customers/login
 +
* customers/order
 +
* customers/register
 +
* customers/reset_password
 +
* index
 +
* page
 +
* password
 +
* product
 +
* search
 +
== Further Reference ==
  
Returns true if the request is using Ajax to render part of the page.
+
* [[Liquid Basics]]
 +
* [[Liquid Tag Reference]]
 +
* [[Liquid Filter Reference]]
 +
* [[Liquid Variable Reference]]
 +
* [[Liquid Paginate Tag|Pagination ]]

Latest revision as of 16:51, 14 July 2022

The Liquid template variable request has the following attributes:

request.parameter

You can access any request parameter by name.

For example, a URL can include a parameter:

http://storedemo.spiffystores.com/?theme=blue

This theme parameter can be accessed by

request.theme

request.host

Returns the host name portion of the URL request.

For example, if we go to http://storedemo.spiffystores.com, then the request.host returns:

storedemo.spiffystores.com

request.url

Returns the complete URL used for this request.

For example, if we go to http://storedemo.spiffystores.com/products/widget, then the request.url returns:

http://storedemo.spiffystores.com/products/widget

request.referer

Returns the referer URL for this request.

For example, if we came to the current page from http://storedemo.spiffystores.com/collections/widgets, then the request.referer returns:

http://storedemo.spiffystores.com/collections/widgets

request.remote_ip

Returns the IP address of the user accessing the page.

request.country

Returns the Country name of the user accessing the page. This information is determined from the IP address, and may not be accurate in all cases. Typically, the results are 99.5% accurate.

The name returned is the ISO Printable name. For example:

Australia

request.country_code

Returns the two character ISO Country Code of the user accessing the page. This information is determined from the IP address, and may not be accurate in all cases. Typically, the results are 99.5% accurate.

The code returned is the ISO Code. For example:

AU

request.province

Returns the Province/State name of the user accessing the page. This information is determined from the IP address, and may not be accurate in all cases. Typically, the results are 99.5% accurate.

The name returned is the ISO Printable name. For example:

New South Wales

request.province_code

Returns the two character ISO Province/State Code of the user accessing the page. This information is determined from the IP address, and may not be accurate in all cases. Typically, the results are 99.5% accurate.

The code returned is the ISO Code. For example:

NSW

request.city

Returns the City name of the user accessing the page. This information is determined from the IP address, and may not be accurate in all cases. Typically, the results are 79% accurate. For example:

Sydney

request.timezone

Returns the Time Zone of the user accessing the page. This information is determined from the IP address, and may not be accurate in all cases. For example, if the user is using a proxy, then the time zone of the proxy server will be returned, rather than that of the user.

The name returned is the standard timezone name. For example:

Australia/Sydney

request.utc_offset

JavaScript code is inserted in every page to detect the UTC offset on a user's computer. This value, in seconds, is set as a cookie, which can be retrieved and returned here.

This value gives an accurate reading of the user's time zone and will probably be more accurate than request.timezone.

No value is available when the initial page is displayed, as the JavaScript to calculate the time zone offset has not had a chance to run.

request.client_time

Returns the best available guess for the current time on the user's computer. If the request.utc_offset value is available, then this is used to calculate the time zone. If this value is not available, then the time zone that has been derived from the IP address is used, and failing that, the local time for the store is used.

request.currency

Returns the local currency of the user, based upon the Country from which the client has accessed the page. This information is determined from the IP address, and may not be accurate in all cases.

AUD

request.user_agent

Returns the user agent string of the user's browser. Each browser returns a unique user agent string, which provides information about the version and features that the browser provides.

Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0 

request.browser

Returns the name of the user's browser.

Firefox

request.browser_version

Returns the version of the user's browser.

25.0

request.browser_platform

Returns the platform of the user's browser. This will be the generic type of operating system that the user is running, such as Windows or Macintosh.

Windows

request.browser_os

Returns the operating system that the user's browser is running under.

Windows 7

request.mobile?

Returns true if the user's browser is running on a mobile device.

request.tablet?

Returns true if the user's browser is running on a tablet device.

request.bot?

Returns true if the request appears to be coming from a robot or web crawler.

request.ajax?

Returns true if the request is using Ajax to render part of the page.

request.locale

Returns the shop_locale of the current request.

request.page_type

Returns the type of the current page. These are the different page types:

  • 404
  • article
  • blog
  • cart
  • collection
  • list-collections
  • customers/account
  • customers/activate_account
  • customers/addresses
  • customers/login
  • customers/order
  • customers/register
  • customers/reset_password
  • index
  • page
  • password
  • product
  • search

Further Reference