Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

FR: Event aliases with date/time #8211

Closed
Anke opened this issue Feb 7, 2016 · 3 comments
Closed

FR: Event aliases with date/time #8211

Anke opened this issue Feb 7, 2016 · 3 comments

Comments

@Anke
Copy link

Anke commented Feb 7, 2016

For SEO reasons it would be nice to have the event date in automaticaly generated aliases, e.g. /eventdetails/fitness-training-2016-02-16.html.

Currently, I think, Contao generates the alias from the event title followed by a unique number if the title isn't unique. Would it be possible to generate the alias from the event title and the start date, then followed by a unique number, if necessary?

@asaage
Copy link

asaage commented Feb 7, 2016

I bet that would interfere with reccuring events.
But you can easily implement Rich-Snippets within your event-Template which is seo-wise much more effective.

@fritzmg
Copy link
Contributor

fritzmg commented Feb 8, 2016

You can set the alias manually or create your own save_callback for the alias field, which implements this automatic behaviour.

@ghost
Copy link

ghost commented Feb 13, 2016

@Anke: I put the following into dcaconfig.php:

// Always prefix the event alias with the start date (yyyy-mm-dd-),
// unless it begins with a date already
$GLOBALS['TL_DCA']['tl_calendar_events']['fields']['alias']['save_callback'][] = 
    function($varValue, DataContainer $dc)
    {
        if (!empty($varValue) and $dc->activeRecord and !preg_match('/^\d{4}-\d{2}-\d{2}-/', $varValue)) {
            $varValue = date('Y-m-d-', $dc->activeRecord->startDate) . $varValue;
        }
        return $varValue;
    }
;

If you want put the date at the end you'd change the pattern to '/-\d{4}-\d{2}-\d{2}$/ and swap date/varValue in the next line. The code does not care (not know) if the alias is automatically generated or not.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants