Body: <p>I'm trying to register a site route in my plugin based on the Entry URL format for a section chosen in the plugin settings.</p>
  
  <p>So if it's the default news section in the Craft install the URL format stored in the database would be: <code>news/{postDate.year}/{slug}</code> or for an About single section it would be: <code>about</code>.</p>
  
  <p>I want to add /login to the end of the url:</p>
  
  <p>e.g. <code>news/2016/amazing-title/login</code> or <code>about/login</code></p>
  
  <p>Then use a login template (e.g. <code>news/_login</code>) in the section for this registered route. </p>
  
  <p>I know how to manually do this with <code>registerSiteRoutes()</code> and the setting stored in a plugin service:</p>
  
  <pre><code>public function registerSiteRoutes()
  {
      $section = craft()-&gt;pluginName-&gt;getSettingsSection();
  
      return array(
          $section . 'REGEX\/login' =&gt; $section . '/_login'
      );
  }
  </code></pre>
  
  <p>What's the best way to convert the Entry URL format for the section into something that can be used in the return array of <code>registerSiteRoutes()</code>?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-02-03T11:52:51.127Z
Comments.Text: You can get a section's URL format like this: `$urlFormat = $section->getUrlFormat();` (provided `$section` is an instance of [`SectionModel`](https://craftcms.com/classreference/models/SectionModel)). Then, you just need a way to resolve URL format variables (i.e. `{slug}` or `{postDate.year}` to valid routing subpatterns, and append the '/login' to the result. Hopefully somebody a bit more versed in regex than myself will be able to help out :)
Comments.UserDisplayName: Mats Mikkel Rummelhoff
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-02-03T20:19:53.370Z
Comments.Text: Thanks for that. I was hoping Craft maybe had a method for converting getUrlFormat() without resorting to my own regex.
Comments.UserDisplayName: Derry Lozano-Hoyland
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-02-17T17:50:53.570Z
Comments.Text: Craft doesn't have a native method to do a conversion like that... it'd have to be custom logic.
Comments.UserDisplayName: Brad Bell
Tags: <plugin-development><plugins><sections><routes><routing>
Title: How do I use the section Entry URL format for registerSiteRoutes() in a plugin?
ThreadText: # How do I use the section Entry URL format for registerSiteRoutes() in a plugin?
  
  (Asked by: username_0 on 2016-02-03)
  
  I'm trying to register a site route in my plugin based on the Entry URL format for a section chosen in the plugin settings.
  
  So if it's the default news section in the Craft install the URL format stored in the database would be: `news/{postDate.year}/{slug}` or for an About single section it would be: `about`.
  
  I want to add /login to the end of the url:
  
  e.g. `news/2016/amazing-title/login` or `about/login`
  
  Then use a login template (e.g. `news/_login`) in the section for this registered route.
  
  I know how to manually do this with `registerSiteRoutes()` and the setting stored in a plugin service:
  
  ```
  public function registerSiteRoutes()
  {
      $section = craft()->pluginName->getSettingsSection();
  
      return array(
          $section . 'REGEX\/login' => $section . '/_login'
      );
  }
  
  ```
  
  What's the best way to convert the Entry URL format for the section into something that can be used in the return array of `registerSiteRoutes()`?
  
  **Tags:** plugin-development, plugins, sections, routes, routing
  
  > **Comments:**
  > **username_1**: You can get a section's URL format like this: `$urlFormat = $section->getUrlFormat();` (provided `$section` is an instance of [`SectionModel`](https://craftcms.com/classreference/models/SectionModel)). Then, you just need a way to resolve URL format variables (i.e. `{slug}` or `{postDate.year}` to valid routing subpatterns, and append the '/login' to the result. Hopefully somebody a bit more versed in regex than myself will be able to help out :)  
  > **username_0**: Thanks for that. I was hoping Craft maybe had a method for converting getUrlFormat() without resorting to my own regex.  
  > **username_2**: Craft doesn't have a native method to do a conversion like that... it'd have to be custom logic.  
  
  ---
  
  ## 0 answers
  
  