Announcement

Collapse
No announcement yet.

Code Sections > pass values

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Code Sections > pass values

    I have been using the ReadyTheme Content Sections more and they are pretty nifty to keep things neat and tidy. This made me wonder if it might not be possible to create Code Sections and within those code sections define an 'interface' to expose properties, attributes or variables which can then be used from the calling page.

    For example say we create a Code Section that did some special customer function, and we want expose values in the interface like so

    define interfacelement: customer_type {

    .name = privatevariable.customer_name;
    .type = privatevariable.customer_type;
    .action =rw /* read write */

    insert code to lookup customer name and read or assign customer special type i.e. wholesale, b2b

    }

    Then we could use this in any page or template and pass or read values from this 'black boxed' code. You could change the code however you wanted and wouldn't have to muck with the page/template calling it as long as the interface elements don't change

    something like

    <mvt:item name="readytheme" param="codesection( 'customer_type' ) action=r,customer_name,customer_type " />

    <mvt:item name="readytheme" param="codesection( 'customer_type' ) action=w,johnsmith,b2b" />


    what appeals to me is
    1-the chance to make the page templates neater and not have a ball of yarn where I'm less likely to change one thing and break some other code unintentionally
    2-the ability to separate the code into into discrete reusable functions, that can be edited without affecting the page they are embedded in as long as the interface remains the same.
    3-the ability to have someone define the code and interface in a codesection and someone else use that with a simple call -without having to expose them to the code - ie I could pay to have code done, with specific properties or attributes exposed, and even if I can't understand the code I can still use it because I know what values the interface expects.

    Hope this makes sense.
    Last edited by habreu; 10-27-17, 03:27 PM.

    #2
    Not sure I should answer this for if I understand, it's an advanced answer IMO. In that giving the flexibility you seem to be looking for it also could mess up things if you do it wrong. So,Here's the thought. If the data being rendered in the readytheme call is created from a template, just use a global variable in the readytheme section. That variable value should then be available after your readytheme item call. It works the other way around too. If you create and fill out a global variable before that call, that global should be available to use in the RT template.

    Notes: that global would only be available on the rendering of that page unless you assign it to a form element also. You need to be careful not to use global variable names that are already used. It's possible to break the page.

    Scott
    Last edited by ids; 10-27-17, 11:22 AM.
    Need to offer Shipping Insurance?
    Interactive Design Solutions https://www.myids.net
    MivaMerchant Business Partner | Certified MivaMerchant Web Developer
    Competitive Rates, Custom Modules and Integrations, Store Integration
    AutoBaskets|Advanced Waitlist Integration|Ask about Shipping Insurance Integration
    My T-shirt Collection is mostly MivaCon T-shirts!!

    Comment


      #3
      Again, not a programmer here but if Miva did something like this I'm guessing it would be possible to create 'private variables' that only have scope within the Code Section. You could pass in a global value to one of these private variables, run your code, and then the returned value could be used to update the global couldn't it?

      ie
      <mvt:item name="readytheme" param="codesection( 'customer_type' ) action=write, g.global1, g,global2" />

      then the content section would assign these values, that have been defined in the interface

      define interfacelement: customer_type {

      .name = privatevariable.customer_name; /* global 1 would be assigned here */
      .type = privatevariable.customer_type; /* global 2 would be assigned here */
      .action =rw /* read write */

      }

      these private variables are used only inside this section, and then the page that called this section would query the interface to get the current values

      ie

      <mvt:item name="readytheme" param="codesection( 'customer_type' ) action=read, value1, value2" />

      g,global1 = value1
      g,global2 = value2

      As for making it accessible without a form - I'm grasping here but let's imagine that the content section is available in some sort of structure, and that the content section has to get assigned to the page you need it on somehow. So if the structure is in memory couldn't it be theoretically accessed on any page it was assigned to?

      ie /*in memory */

      structure customer_type
      .name *currently holds value passed from global1
      .type *currently holds value passed from global2

      then using the codesection tag you could read/write/update/flush these values on any page that it was assigned to.

      Hope this makes sense.
      Last edited by habreu; 10-27-17, 12:40 PM.

      Comment


        #4
        I've actually tried to use Content sections to do things like this...and found one small, but basically exclusionary issue. Content sections, when called, output an html div wrapper...so, you can use them say in the "head" section of your template. We are playing with an idea that do pretty much what you are looking to do (and more of course) including the control of passing in variables, protect scope, and giving you greater access control. Its a bit out (like maybe end of year) due to project loads, but drop us a line or two of things you'd like to do with something like this.
        Bruce Golub
        Phosphor Media - "Your Success is our Business"

        Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
        phosphormedia.com

        Comment

        Working...
        X