Code Monkey home page Code Monkey logo

like's Introduction

Like for Craft CMS

A simple plugin to connect to Like's API.


Installation

  1. Download the latest release of the plugin
  2. Drop the like plugin folder to craft/plugins
  3. Install Like from the control panel in Settings > Plugins

Templating

Like button

{% if currentUser %}
    {% if craft.like.isLike(element.id) %}
        <a class="btn btn-default" href="{{actionUrl('like/remove', {id:element.id})}}"><span class="glyphicon glyphicon-star"></span> Unlike</a>
    {% else %}
        <a class="btn btn-primary" href="{{actionUrl('like/add', {id:element.id})}}"><span class="glyphicon glyphicon-star"></span> Like</a>
    {% endif %}
{% else %}
    <a class="btn disabled btn-primary" href="#">Like</a>
{% endif %}

List likes for an element

{% set likes = craft.like.getLikes(element.id) %}

{% if likes|length > 0 %}

    {% for like in likes %}
        <a href="#">
            {% if like.user.photoUrl %}
                <img src="{{like.user.photoUrl}}" width="34" class="img-rounded" data-toggle="tooltip" data-original-title="{{like.user.email}}" />
            {% else %}
                <img src="http://placehold.it/34x34" data-toggle="tooltip" class="img-rounded" data-original-title="{{like.user.email}}">
            {% endif %}
        </a>
    {% endfor %}

{% endif %}

Your Likes

Entries and asset that you like.

Entries:

{% set entries = craft.like.getUserLikes('Entry') %}

{% if entries %}
    <ul>
        {% for entry in entries %}
            <li>{{entry.title}}</li>
        {% endfor %}
    </ul>
{% else %}
    <p>You haven't liked any entry yet.</p>
{% endif %}

Assets:

{% set assets = craft.like.getUserLikes('Asset') %}

{% if assets %}
    <div class="row">
        {% for asset in assets %}
            <div class="col-md-4">
                <img class="thumbnail img-responsive" src="{{asset.url({width:200, height: 140})}}" />
            </div>
        {% endfor %}
    </div>
{% else %}
    <p>You haven't liked any asset yet.</p>
{% endif %}

API

LikeVariable

  • isLike($elementId)
  • getLikes($elementId = null)
  • getUserLikes($elementType = null, $userId = null)

like's People

Contributors

benjamindavid avatar carlcs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.