Created
January 18, 2017 16:45
-
-
Save bfodeke/253f40451bcd8836f101ec74c3f6e681 to your computer and use it in GitHub Desktop.
Demonstrates how to create a theme function in javascript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ($) { | |
// Declare the theme function. | |
Drupal.theme.prototype.projectTeaser = function(image_url, title, url) { | |
return '<div class="teaser"><img class="teaser--image" src="' + image_url + '" /><h2 class="teaser--title">' + title + '</h2><a class="teaser--link" href="' + url +'">View Project</a>'; | |
} | |
Drupal.behaviors.gtpePurchaseOrder = { | |
attach: function (context, settings) { | |
// Call the theme function like so. It should return themed markup. | |
var teaser = Drupal.theme('projectTeaser', 'http://placehold.it/300x300', 'I did this fancy stuff', 'http://npr.org'); | |
// Append it to a div. | |
$('.project-teaser').append(teaser); | |
} | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment