Templating

# Available Variables

Variable
craft.stravaSync.connectUrl(options)
craft.stravaSync.disconnectUrl(options)

# connectUrl

Use the connectUrl method to register and login a user via Strava oAuth.

<a href="{{ craft.stravaSync.connectUrl() }}">Login with Strava</a>

Optionally pass a redirect param to the method to overwrite the Login Redirect plugin setting, and redirect them when they have successfully logged in:

<a href="{{ craft.stravaSync.connectUrl({ redirect: '/success'  }) }}">Login with Strava</a>

# disconnectUrl

Use the disconnectUrl method to disconnect the current logged in user from Strava and unlink it from their Craft CMS user account:

<a href="{{ craft.stravaSync.disconnectUrl() }}">Disconnect from Strava</a>

Optionally pass a redirect param to the method redirect the user after they have disconnected:

<a href="{{ craft.stravaSync.disconnectUrl({ redirect: '/account'  }) }}">Disconnect from Strava</a>

# connected

Use the connected method to check to see if the current logged in user has connected their Strava account:

{% if craft.stravaSync.connected %}
   <a href="{{ craft.stravaSync.disconnectUrl() }}">Disconnect from Strava</a>
{% else %}
   <a href="{{ craft.stravaSync.connectUrl() }}">Connect to Strava</a>
{% endif %}

# request

Use the request method to get the authorised users data from Strava. Whether this is the users Activities, Clubs, Profile data etc.

WARNING

It's highly recommend caching this data for X amount of time using Craft {% cache %} twig tags or a plugin like Blitz. This will reduce the amount of requests to Strava and make templates load better.

{% set athleteActivities = craft.stravaSync.request(
   'getAthleteActivities'
) %}

{% for activity in athleteActivities %}
   {{ activity.name }} / {{ activity.distance }}<br>
{% endfor %}

Depending on your scope type when you authorised the account, the supported request types are:

  • getAthlete
  • getAthleteClubs
  • getAthleteRoutes
  • getAthleteActivities
  • getAthleteZones
  • getAthleteStarredSegments
  • getActivity
  • getActivityComments
  • getActivityKudos
  • getActivityPhotos
  • getActivityZones
  • getActivityLaps
  • getGear
  • getClub
  • getRoute
  • getSegment
  • getSegmentLeaderboard
  • getStreamsActivity
  • getStreamsEffort
  • getStreamsSegment
  • getStreamsRoute

# Onboard

Because the Strava API doesn't give us access to the authorised users email address, we need to collect this to create a Craft CMS user. This is done by placing the following code on to a template and ensuring this template is the one accessible from the Onboard Redirect plugin setting:

<form method="post" accept-charset="UTF-8">

   {{ getCsrfInput() }}
   {{ actionInput('strava-sync/user/register') }}

   <label for="email">Email Address</label>
   <input type="email" name="email" id="email" required>
   {% if craft.app.session.getFlash('error')|length %}
      {{ craft.app.session.getFlash('error') }}
   {% endif %}

   <button>Continue</button>

</form>