Sourcefabric Manuals

 English |  Español |  Français |  Italiano |  Português |  Русский |  Shqip

Newscoop 4.2 Cookbook

Making author profile page

 

Listing from Article author list to user profile

Inside an article, a typical link to author profile could be like this:

{{ list_article_authors }}
  {{ if $gimme->author->user->defined }}
        <a href="{{ $view->url(['username' => $gimme->author->user->uname], 'user') }}">
  {{ /if }}
  
  {{ $gimme->author->name }}
  
  {{ if $gimme->author->user->defined }}
        </a>
  {{ /if }}
  
{{ /list_article_authors }}

The important new feature here is the check if user is "defined".

{{ if $gimme->author->user->defined }}

If the user is "defined" that means that the author has a link to a registered user. If this is the case, a link is presented to the profile:

<a href="{{ $view->url(['username' => $gimme->author->user->uname], 'user') }}"> 

A link will be created following the structure /user/profile/username - where "username" is differing depending on the author listed.

 

The user profile page

IMPORTANT

We will always use the template user_profile.tpl in the root directory of the theme. If the template is not present a system template will be displayed.

Display user profile data

If user is an author we want to use author data as much as possible because author biography is translateable.

<img src="{{ $user->image(<width>, <height>) }}" />
<h4>
 {{ if $user->author->defined }}
      {{ $user->author->biography->first_name }} {{ $user->author->biography->last_name }}
 {{ else }}
      {{ $user->first_name }} {{ $user->last_name }}
 {{ /if }}
</h4>
 
{{ if $user->author->defined }}
   <p>
      {{ $user->author->biography->text }}
   </p>
{{ else }}
   <p>
      {{ $user['bio']|escape }}
   </p>
{{ /if }}

 To learn more please check user, author and author biography object references.

 

If user is author, list articles

The user can also be an author, in which case the profile page can display a list of all articles the author is related to. This is the case if in the admin interface a link between an author and a user profile has been established in the profile editing area. If this is the case, $user->isAuthor() is true.

Firstly, check if the user is an author and if so, create the variable $escapedName containing the name with an escaped whitespace. This means that "First and Lastname" will be converted to "First\ and\ Lastname" - which we need in the list command below.

{{ if $user->isAuthor() }}
  {{ $escapedName=str_replace(" ", "\ ", $user->author->name) }}
{{ /if }}

Now we have a variable that only exists IF the user whose page we visit is also an author. We will use this variable in the article list we create now. You can see that the variable is used in the constraints of the list. This means that no list is created, if the user is not an author. We ignore publication, issue and section to list all articles related with the user / author.

{{ list_articles ignore_publication="true" ignore_issue="true" ignore_section="true" constraints="author is $escapedName" order="bypublishdate desc" }}
     ...
     <a href="{{ $gimme->article->url }}" >{{ $gimme->article->title }}</a>
     ...
{{ /list_articles }}

There has been error in communication with Booktype server. Not sure right now where is the problem.

You should refresh this page.