Skip to content

Instantly share code, notes, and snippets.

@Antoinebr
Forked from johnsfuller/hubspot-hubl.html
Created October 11, 2021 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Antoinebr/8ecc28d73f0ab2bd59ed66177d08dd17 to your computer and use it in GitHub Desktop.
Save Antoinebr/8ecc28d73f0ab2bd59ed66177d08dd17 to your computer and use it in GitHub Desktop.
WordPress/PHP & HubSpot/HubL Comparison Cheat Sheet
<!-- 👇 Scroll down 👇 -->
{# variables #}
{% set my_variable = 'Hello world' %}
{# get variables from somewhere else #}
{% import 'path/to/hubl-variables.html' as site_vars %}
{{ site_vars.my_external_variable }}
{# rendering / printing #}
{{ my_variable }}
{{ my_variable|pprint }}
{# if #}
{% if my_variable == 'Hello world' %}
do_something
{% elif my_variable == 'Goodbye world' %}
do_something_else
{% else %}
do fallback
{% endif %}
{# functions #}
{% macro do_this( arg ) %}
<p>{{ arg }}</p>
{% end_macro %}
{{ do_this( my_variable ) }}{# renders <p>Hello world</p> #}
{% import 'path/to/external/macros.html' as macros %}
{# for loops #}
{% for iterable in dict %}
{{ iterable.property }}
{% endfor %}
{% for key, val in dict.items() %}
{{ key }} {{ val }}
{% endfor %}
{# HubSpot variables #}
{{ contents }} {# blog listing {% for (content in contents) %} #}
{{ content }} {# page or post or email #}
{# title #}
{{ content.name }}
{# content #}
{{ content.post_body }}{# blog post #}
{{ content.email_body }}{# email #}
{{ content.<value> }}{# value is name of any module #}
{# content vars #}
{{ content.next_post_featured_image }}
{{ content.next_post_featured_image_alt_text }}
{{ content.next_post_name }}
{{ content.next_post_slug }}
{{ content.previous_post_featured_image }}
{{ content.previous_post_featured_image_alt_text }}
{{ content.previous_post_name }}
{{ content.previous_post_slug }}
{{ content.tag_list }}
{{ content.blog_post_author }}
{{ content.author_name }}
{{ content.post_summary }}
{{ content_id }}
{{ content.<module_instance_name> }}
{{ content.absolute_url }}
{{ content.tag_list }}
{{ content.name }}
{{ content.created }}
{# menu #}
{% module "menu" path="@hubspot/menu" %}
{# menu (tag version) #}
{% menu 'primary_nav'
flow='horizontal',
max_levels=2,
flyouts=true,
site_map_name='default'
%}
{# custom menu / walker #}
{% set nav = menu('default') %}
<nav>
{% for link in nav.children %}
<a href="{{ link.url }}">{{ link.label }}</a>
{% if link.children %}
<ul>
{% for child in link.children %}
<li>
<a href="{{ child.url }}">{{ child.label }}</a>
</li>
{% endif %}
</ul>
{% endif %}
{% endfor %}
</nav>
{# site header & footer #}
{% global_partial path='path/to/header.html' %}
{% global_partial path='path/to/footer.html' %}
{# template partials #}
{% include 'custom/page/web_page_basic/sidebar-one.html' %}
<!-- 👇 Scroll down 👇 -->
<!-- variables -->
<?php $my_variable = 'Hello world'; ?>
<!-- rendering / printing -->
<?php echo $my_variable; ?>
<?php var_dump( $my_variable ); ?>
<!-- if -->
<?php if ( $my_variable === 'Hello world' ) : ?>
do_something
<?php elseif ( $my_variable === 'Goodbye world' ) : ?>
do_something_else
<?php else : ?>
do fallback
<?php endif; ?>
<!-- functions -->
<?php
function do_this( $arg ){
echo '<p>' . $arg . '</p>';
}
?>
<?php do_this( $my_variable ); ?><!-- renders <p>Hello world</p> -->
<?php require get_template_directory() . '/path/to/external/functions.php'; ?>
<!-- for loops -->
<?php
// 1. foreach();
// 2. for();
// 3. while();
?>
<!-- WordPress variables -->
<?php
while ( have_posts() ) :
the_post();
endwhile;
?>
<!-- title -->
<?php the_title(); ?>
<!-- content -->
<?php the_content(); ?>
<!-- content vars -->
<?php
next_post_link();
previous_post_link();
the_category();
the_author();
the_excerpt();
the_ID();
the_meta();
the_shortlink();
the_tags();
the_title();
the_time();
?>
<!-- menu -->
<?php
wp_nav_menu(
array(
'theme_location' => 'primary',
'depth' => 2
)
);
?>
<!-- custom menu / walker -->
<?php
class Nav_Custom_Walker extends Walker_Nav_Menu {
// your logic / markup
}
wp_nav_menu(
array(
'theme_location' => 'primary',
'walker' => new Nav_Custom_Walker()
)
);
?>
<!-- site header & footer -->
<?php get_header(); ?>
<?php get_footer(); ?>
<!-- template partials -->
<?php get_template_part( 'template-parts/header/site-nav' ); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment