Sign in to follow this  
louisstephens

Using hanna to output js/php

Recommended Posts

I have a repeater with a text field where I would like to use hanna code (to make it easier on the user) so the user can define the action of a image that is in the repeater. For example:

1. The image should have an external link:

- the user can just type in the url

2. The image, when clicked, should be printable (using print.js)

- the user can just type [[print_image]]

That works just fine, but I am running into an "issue". The code I need to use to print is:

onclick="printJS({printable: 'path_to_image', type: 'image'});"

I can put that into the hanna code as plain text, but I have no idea how to get the image from the repeater item and pass to "path_to_image". Is this even possible?

Share this post


Link to post
Share on other sites
25 minutes ago, louisstephens said:

I have a repeater with a text field where I would like to use hanna code (to make it easier on the user) so the user can define the action of a image that is in the repeater. For example:

1. The image should have an external link:

- the user can just type in the url

2. The image, when clicked, should be printable (using print.js)

- the user can just type [[print_image]]

That works just fine, but I am running into an "issue". The code I need to use to print is:


onclick="printJS({printable: 'path_to_image', type: 'image'});"

I can put that into the hanna code as plain text, but I have no idea how to get the image from the repeater item and pass to "path_to_image". Is this even possible?

Yes, this should be doable!

https://github.com/ryancramerdesign/ProcessHannaCode (Check PHP Usage Notes)

If I understand the docs correctly, the $page variable context will be the repeater page where the image field is. 

Share this post


Link to post
Share on other sites

Thanks elabx. I might need a bit more help here. I currently have [[print_image]]:

onclick="printJS({printable: 'path_to_image', type: 'image'});"

But I also need "path_to_image" filled out, but I wasnt sure how to echo the php inside of a hanna code that was set to "text/html". Perhaps I am making this more difficult than it needs to be, but I was trying to work around using if statements in my actual template to check whether the user typed a url vs the shortcode.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Robin S
      Another little admin helper module...
      Template Field Widths
      Adds a "Field widths" field to Edit Template that allows you to quickly set the widths of inputfields in the template.

      Why?
      When setting up a new template or trying out different field layouts I find it a bit slow and tedious to have to open each field individually in a modal just to set the width. This module speeds up the process.
      Installation
      Install the Template Field Widths module.
      Config options
      You can set the default presentation of the "Field widths" field to collapsed or open. You can choose Name or Label as the primary identifier shown for the field. The unchosen alternative will become the title attribute shown on hover. You can choose to show the original field width next to the template context field width.  
      https://github.com/Toutouwai/TemplateFieldWidths
      https://modules.processwire.com/modules/template-field-widths/
    • By louisstephens
      So I have a form, once completed, will create new pages. All in all, this is eazy-peezy for me now. I guess I need a bit of guidance on how to actually structure the rest of my code.  I thought I could just write a function (_func.php) and pass the fields to the function and let it do its' thing. However, I am kinda hitting a road block when I do it this way. 
      I currently am passing first name, last name, city, state (options field), and making pages based on the first/last names. I guess where I run into some issues is I am trying to check to see if the "page" already exists, and if it does, throw out an error:
      In the home template:
      if(isset( $_POST['submit'])) { $firstName =Trim (stripslashes($_POST['firstname'])); $lastName = Trim(stripslashes($_POST['lastname'])); $fullName = $firstName . $lastName; $city = Trim(stripslashes($_POST['city'])); $state = Trim(stripslashes($_POST['state'])); $lowerCaseName = strtolower($fullName); $people = $pages->find("template=person"); foreach ($people as $person) { $checkFirstName = $person->first_name; $checkLastName = $person->last_name; $checkFullName = $checkFirstName . $checkLastName; if ($checkFullName === $lowerCaseName) { echo "<p>" . "This person has already created a page. Please choose a different name." . "</p>"; } else { echo "hey"; processNewPerson(need_to_pass_person_details_to_function); } } // end foreach In _func.php:
      function processNewPerson($list) { $u = new Page(); $u->template = "person"; $u->parent = wire('pages')->get("/people/"); $u->title = ; $u->first_name = ; $u->last_name = ; $u->state = ; $u->city = ; $u->save(); $u->setOutputFormatting(false); } I am a little unsure of how to actually pass all the information to the template, as well as if this is even the best approach to do this. Would it make more sense to do this in a class, or keep it the way it is?
    • By louisstephens
      I have done a bit of searching, but I can not seem to find an actual answer. I have a list of services as child pages under "Services". I can output the services just fine, but I cant wrap my head around how to group them "alphabetically" like:
      Services A - Service "A" 1 - Service "A" 2 - Service "A" 3 B - Service "B" 1 - Service "B" 2 - Service "B" 3 C - Service "C" 1 - Service "C" 2 - Service "C" 3 Has anyone achieved this type of functionality before?
    • By Falk
      Hi!
      I have lots of blogposts in my pagetree and I want the pagelabel to include the value of the post’s datefield (only the year).
      Adding date | title in the template settings results in something like…
      1536012000 | my blogpost title
      Is it possible to convert the timestamp to a readable date?