Newscoop 4 Cookbook

URL

The URL object follows the changes in the template environment, meaning that every time an object in the environment changes the URL object is updated. It has the following properties:

  • is_valid: returns true if the URL was valid, false otherwise. On invalid URLs Newscoop returns a "404 not found" HTTP response. This option only works in Newscoop 3.4.0 and newer versions. Here is example code which could be used in a 404 page:
{{ if !$gimme->url->is_valid }}  <h3>The requested page was not found.</h3> {{ set_language name=`$gimme->publication->default_language->english_name` }}   {{ set_current_issue }} {{ else }}     <!-- display content --> {{ /if }} 
  • uri: returns the complete link URI, and is equivalent to:
{{ $gimme->url->uri_path }}?{{ $gimme->url->url_parameters }} 
  • uri_path: returns only the path part of the URI, the part before the parameters list. For example, if /en/1/2/3?param1=text was the full URI, uri_path is /en/1/2/3
  • url: returns the complete URL in the form:
http://<default_site_alias><uri> 
  • url_parameters: returns a string containing the runtime environment parameters in URL format
  • form_parameters: the runtime environment parameters in HTML form format:
<input type="hidden" name="<param_name>" value="<param_value>">
  • base: returns the URL base in the form:
http[s]://<server_name>[:<port>]

The port is not displayed if it's value was the default value (80 for HTTP, 443 for HTTPS)

  • path: equivalent to uri_path
  • query: equivalent to url_parameters
  • type: returns the identifier of the URL type set in the publication (see also "Creating A Publication" in Newscoop for Journalists and Editors)
  • request_uri: equivalent to uri
  • scheme: one of the following values: http, https
  • host: the host name from the URL
  • port: the port to which the request was made
  • language: returns the language object corresponding to the language set in the URL; this value is always the same as the language in the environment (see the chapter "Language" for more details)
  • publication: returns an object corresponding to the publication identified by the <server_name>; this value is always the same as the publication in the environment (see the chapter "Publication" for more details)
  • issue: returns an object corresponding to the issue specified in the URL (unset if the issue was not specified); this value is always the same as the issue in the environment (see the chapter "Issue" for more details)
  • section: returns an object corresponding to the section specified in the URL (unset if the section was not specified); this value is always the same as the section in the environment (see the chapter "Section" for more details)
  • article: returns an object corresponding to the article specified in the URL (unset if the article was not specified); this value is always the same as the article in the environment (see the chapter "Article object and attachment, comment, location" for more details)

The URL object has the following functions:

  • get_parameter(<parameter_name>): returns the value of the given parameter, null if not set
  • set_parameter(<parameter_name>, <parameter_value>): set the given parameter to the given value
  • reset_parameter(<parameter_name>): unset the given parameter