npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wp-timber-cli

v0.4.1

Published

CLI for wordpress and Timber-WP with Twig

Downloads

23

Readme

##Requirements You must be using Timber for WordPress.

##Installation run npm install --save wp-timber-cli inside your root WordPress theme directory.

##Usage Timber CLI will create a WordPress PHP template and corresponding twig template and automatically create some default Timber stuff.

###Create Templates From the command line, run wp-timber -c <type> <name> where type is the type of template (page, single, archive) and name is, you guessed it, the name of the template.

Example Output

wp-timber -c page about-us

Creates page-about-us.php in your theme's root directory, and /views/pages/page-about-us.twig. If you don't have a views directory it will be created for you.

Inside the created .php file is a very basic Timber template that renders the corresponding twig template that was also created.

page-about-us.php

<?php

$context = Timber::get_context();
$post = new TimberPost();
$context["post"] = $post;
Timber::render("/views/pages/page-test.twig", $context);

?>

###Create Query You can create a basic WordPress query for an existing page template, or when create a new template using this CLI.

Existing Template

wp-timber -q page-about.php custom-post-type

When Create a New Template

wp-timber -c page about -q custom-post-type

Output

<?php

 $custom_post_types_args = array(
  "post_type"     => "custom-post-type"
 );

$context = Timber::get_context();
$post = new TimberPost();
$context["post"] = $post;
$context["custom_post_types"] = Timber::get_posts($custom_post_types_args);
Timber::render("/views/pages/page-about.twig", $context);

?>

###Remove Templates

wp-timber -r page about-us

This will find a .php template called page-about-us.php in the root theme directory and delete it, as well as the corresponding twig template in /views/pages/.

###Create Subclasses

Create a subclass of a built-in Timber class (TimberPost, TimberTerm etc.) in the lib directory by running wp-timber -s <class> <name>, where class refers to the class to extend and name is the name assigned to the new subclass. Site, term, post, menu, menuitem, and user are all accepted as arguments for the base class.

Output

wp-timber -s post TestPost

Creates TestPost.php in the /lib directory, with the following boilerplate:

<?php

Class TestPost extends TimberPost { 
  // Add methods and properties here 
} 

?>

This will find a .php template called page-about-us.php in the root theme directory and delete it, as well as the corresponding twig template in /views/pages/.

###Build from a Config file With Timber CLI you can generate a series of templates with queries from a configuration file. Create a .timber file that contains JSON to generate as many templates with queries as you want.

Here's an example config file:

{
  "page": {
    "blog": {
      "queries":{
        "news": {
          "post_per_page": 10,
          "orderby": "title"
        },
        "custom-posts": {
          "post_per_page": 20,
          "orderby": "date"
        }
      }
    },
    "about-us": {}
  },
  "archive": {
    "events": {},
  },
  "single": {
    "event": {}
  }
}

Running wp-timber build will generate the following PHP/twig templates:

  • page-blog.php with two queries: one for 'news' post type and one for 'custom-posts' and views/pages/page-blog.twig file
  • page-about-us.php and views/pages/page-about-us.twig
  • archive-events.php and views/archives/archive-events.twig
  • single-event.php and views/singles/single-event.twig