Mashup Popup template

Home Forums MapPress Support Mashup Popup template

This topic contains 11 replies, has 2 voices, and was last updated by  Chris 2 days, 19 hours ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #18269

    monsieurgraphiste
    Participant

    Hi Chris,

    I’m trying to edit the template for POI mashup.

    here is my code

    {{{poi.title}}}

    {{{poi.thumbnail}}}

    {{poi.props.annonce_surface}} m²
    {{poi.props.annonce_chambres}} chambre(s)
    {{poi.props.annonce_sdb}} SDB
    {{poi.props.annonce_prix}} €

    I would to like to change poi.props.annonce_prix with PHP CODE :

    Thanks for your help

    #18273

    Chris
    Keymaster

    Hi,

    You can do calculations, but you’ll need to pass the resulting value to the template. There are two ways to do this:

    1) Calculate the value when a post is saved (using the WP ‘save_post’ action). Store the result in a custom field. Then, you can display the custom field in the template.

    2) There’s a MapPress filter to do these calculations whenever the map is displayed. This should get you started if you want to take that approach:
    https://mappresspro.com/mappress-documentation/#toc-mappress-templating

    #18312

    monsieurgraphiste
    Participant

    Hi Again Chris,

     

    Is it possible to display a custom field is not empty <i class=””fal” aria-hidden=””true””></i> {{poi.props.annonce_surface}} m²

     

    For the calculation stuff, i don’t see the <code class=”prettyprint prettyprinted”><span class=”pln”>mashup</span><span class=”pun”>-</span><span class=”pln”>tmpl</span><span class=”pun”>-</span><span class=”pln”>popup</span><span class=”pun”>.</span><span class=”pln”>php</span> file ?

    Could you help me on this, thank you

    #18313

    Chris
    Keymaster

    Hi,

    The templates are editable via the MapPress settings screen.  They’re saved in your theme directory, and the originals are in the /templates directory of the plugin.  There’s general information about this in the MapPress documentation.

    I think you are asking to display a field only if non-empty.  For that, you would need some javascript in the template.  You can do a simple if statement by using three braces:

    {{{ (poi.props.annonce_surface) ? poi.props.annonce_surface : 'empty'}}}

    Or, make a conditional block using ‘<#’ and ‘#>’ around the JavaScript parts:

    <# if (poi.props.annonce_surafce) { #>
    <i class=””fal” aria-hidden=””true””></i> {{poi.props.annonce_surface}} m²
    <# } #>

     

    #18314

    monsieurgraphiste
    Participant

    Hi Chris,

    That works perfectly. Thanks for your quick help.

    I don’t understand about point 2 on calculations ?

    Could you please give me an example.

     

    Many thanks

    #18315

    monsieurgraphiste
    Participant

    If calculation is not possible, i just need another function.

     

    if a custom_post_type is from taxonomy value i need to add text to price label

    – location i need to add / month

    – summer location /night.

    Is it possible to add this to the mashup-popup template ?

    <span class=”price label label-warning”> {{poi.props.annonce_prix}} € <?php if ( has_term( ‘location’, ‘offre’ ) ) echo ‘<small>/ mois</small>’; ?> <?php if ( has_term( ‘location-saisonniere’, ‘offre’ ) ) echo ‘<small>/ nuit</small>’; ?></span>

    Thank you

     

    #18316

    Chris
    Keymaster

    I’m not sure if it’s clear, but PHP code can’t be used for calculation in the template itself.  The templates use JavaScript, and they only execute when a popup is displayed.

    So, using has_term() in the template won’t do anything useful.  Instead, you need to do the calculations for each post using the mappress_poi_props filter.  The results are then passed to the template for display using the poi.props array.

    There’s an example of using the filter to pass a custom value to the template here in the MapPress documentation:

    https://mappresspro.com/mappress-documentation/#toc-mappress-templating

     

    #18317

    monsieurgraphiste
    Participant

    Hi Again Chris,

    Thanks for your reply,

    I just want to add custom text depending to the taxonomy of the post.

    Can we retrieve taxonomy ID or slug ?

    {{poi.props.annonce_prix}} € (ADD /month or /night)

    how can i achieve this, please ?

    Thanks

    #18318

    monsieurgraphiste
    Participant

    Hi again Chris,

    Sorry for all my questions but i modified the price value to a function so i can display the price easier on the website.

    Is it possible to pass the function on the POI template ?

     

    function annonce_post_price(){ ?>
    <span class=”price label label-warning”> <?php $price = annonce_detail(‘annonce_prix’); echo number_format( $price, 0, ‘,’, ‘ ‘ );?> € <?php if ( has_term( ‘location’, ‘offre’ ) ) echo ‘<small>/ mois</small>’; ?> <?php if ( has_term( ‘location-saisonniere’, ‘offre’ ) ) echo ‘<small>/ nuit</small>’; ?></span>
    <?php }

     

    Thanks

    #18319

    Chris
    Keymaster

    Hi,

    Have you read the documentation yet?  There’s an example there of using the PHP filter to pass a value to the template.

    In this case, you would use that filter to pass the result of your function to the template as a property, then display that property in the template.

     

    #18321

    monsieurgraphiste
    Participant

    Hi Chris,

    Are you talking about this functionnality :

    <?php
    function myfilter($props, $postid, $poi) {
    $props[‘message’] = “Hello from post ” . $postid;
    return $props;
    }
    add_filter(‘mappress_poi_props’, ‘myfilter’, 10, 3);
    ?>

     

    Thanks

    #18322

    Chris
    Keymaster

    Yes, but you would use your calculation to return the value.  It would look something like this (this is just pseudo-code – I haven’t tested it):

    function myfilter($props, $postid, $poi) {
      $price = annonce_detail('annonce_prix');
      $html = number_format( $price, 0, ',', ' ' ) . ' € ';
      if ( has_term( 'location', 'offre' ) )
        $html .= '<small>/ mois</small>';
      if ( has_term( 'location-saisonniere', 'offre', $postid ) )
        $html .= '<small>/ nuit</small>';
      $props['prix'] = $html;
      return $props;
    }
Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.