To create urls for e.g. links within your templates / sites managed by the Hublify-CMS, use the built-in hublify url-functions.

Do not do this! ;)

In every html source code or Hublify template you can write your urls and links hardcoded like :

(BAD example)

<a href="https://mySite.com/a/path/to/something-interesting">go here!</a>

Well, not much to say. :) This is not flexible and reliable, at all. It's just a matter of time when such a link will be outdated.

At least for site-internal urls.

You are better off, using the helpful hublify-url-functions, outlined below!

...except

Of course to every rule there are exceptions.

So, whenever you link to some outside urls you will probably end up writing hardcoded urls. And that's OK since Hublify does not know really anything about therse urls.


Render-Target: "website"

Hublify brings multiple functions with which you can achieve full flexibility. For growing and (SEO-based) changing content, data, pages, site-structures, redirects, ...



url(...)

Getting an absolute url to path within the current site, defined in Hublify-CMS.

    /**
     * Returns an url-string
     *
     * E.g. to be used for "<a href"{{ url(...) }}">...
     *
     * @param string $path
     *
     * @param string|object|null $params Optional parameters appended as URL-GET-Params.
     *
     * @param string|null $schema Either "http" or "https". (not yet implemented!)
     *
     * @return string
     */

url(string $path, $params = null, string $schema = null): string


pageLinkUrl(...)

Getting an absolute url to a page, defined in Hublify-CMS.

pageLinkUrl(string $pageLabel, $params = null, string $schema = null): ?string

  • pageLabel - string This is unique label of the page you want to link to.
  • params - array Optional URL-GET-parameters to be appended.
  • schema - string Optional (default NULL) E.g. "https". In most cases you should set this to NULL and leave it to Hublify to determine the correct schema / url.
<a href="{{ hublify.pageLinkUrl( 'myTrgPageLabel', {'myGETVar':'Foo Bar!'}) }}"> goto Page! </a>


contentLinkUrl(...)

Getting an absolute url to a given content-record, defined in the Hublify-Content-DB.

/**
     * Returns an url to a CDB-record.
     * In order to be able to use this, you have to have your CDB (-contentype) configured properly!
     * This should take into account already all pretty-url-writings etc.!
     *
     * @param string $contentType CDB content-type
     * @param string|null $contentId xc__label of record you want to link to
     * @param array|null $params Additional URL-GET-params to append in link
     * @param string|null $languageIso Optional language-Code (default NULL / current site-language)
     * @param string|null $schema
     * @return string|null The absolute url. E.g. "https://www.your-domain.com/path/to/record
     */

contentLinkUrl(string $contentType, string $contentId = null, array $params = null, string $languageIso = null, string $schema = null): ?string


contentCategoryLinkUrl(...)

Getting an absolute url to a given content-category, defined in the Hublify-Content-DB.

 /**
     * Returns an url to a CDB-category.
     *
     * This should take into account already all pretty-url-writings etc.!
     *
     * @param string $nodeCode The category's node_code
     * @param array|null $params Additional URL-GET-params to append in link
     * @param string|null $catalogLabel The catalog-label this nodeCode belongs to
     * @param string|null $languageIso Optional language-Code (default NULL / current site-language)
     * @param string|null $schema
     * @return hublify_linkData|null
     */

contentCategoryLinkUrl(string $nodeCode, array $params = null, string $catalogLabel = null, string $languageIso = null, string $schema = null): ?string


productLinkUrl(...)

There is a special function to get the absolute url for a product. All you need is its pcode.
This is especially for "products" (PIM) only.

{% set pcode = "prd123" %}
<a href="{{ hublify.productLinkUrl(pcode) }}"> goto Product! </a>


categoryLinkUrl(...)

Getting an absolute url to a category, defined in Hublify-PIM and Hublify-CMS.

This is especially for "product-categories" (PIM) only.


categoryLinkUrl(string $categoryCode, $params = null, string $schema = null): ?string



redirect(...)

Execute directly a browser-redirect to any given url.

Per default a 302-HTTP-header redirect is triggered.

redirect(string $url, int $status = 302)

Status can one of the following HTTP-Codes:

  • 302 (default) Executes "Moved temporarily" redirect
  • 301 Executes a "Moved Permanently"
  • 303 "See Other"
  • 304 "Not Modified"


Example

{% set dontCare = hublify.redirect('https://google.com') %}


redirectPage(...)

Execute directly a browser-redirect to a given page-label, defined in the Hublify-CMS.

redirectPage(string $pageLabel, $params = null, string $schema = null, int $status = 302)

Example

{% set dontCare = hublify.redirectPage('myaccount') %}



Render-Target: "Hublify App"

When you want to get urls pointing to or into your Hublfiy App's backend, you can use these functions.


appUrl(...)

Getting an absolute main-url to the Hublify App, itself.

    /**
     * Returns the base url for hublify (backend) app
     *
     * Use this for creating deep-links into the app.
     *
     * @return string|null
     */

    public function appUrl(): ?string


appUrlGotoDataset(...)

Gets an absolute url to the default dataset's record-list within the Hublify App.

/**
     * Returns a model-related absolute url , deep-linking into the hublify-app
     *
     * @param string $datasetLabel Url shall point to this dataset (model)
     * @param string $pageType E.g. "list"
     * @param array|null $params Optional associative array for URL-GET-Params
     *
     * @return string|null Returns an absolute url. Returns NULL if no base-url for app could be determined.
     */

appUrlGotoDataset(string $datasetLabel, string $pageType, array $params = null): ?string


appUrlGotoRecord(...)

Gets an absolute url to the default dataset's record-detail view within the Hublify App.

/**
  * Returns a model-related absolute url , deep-linking into the hublify-app
  *
  * @param string $model Url shall point to this model
  * @param string $primaryValue The primary key's value identifying the record.
  * @param string $pageType E.g. "detail|edit"
  *
  * @param array|null $params Optional associative array for URL-GET-Params
  *
  * @return string|null Returns an absolute url. Returns NULL if no base-url for app could be determined.
  */

appUrlGotoRecord(string $model, string $primaryValue, string $pageType = 'detail', array $params = null): ?string