Jump to content

MarkupShortcodes


Nico Knoll
 Share

Recommended Posts

  • 2 months later...

Hi Nico,

I am using your MarkupShortcodes for a new website I'm creating. It's a music theory and guitar lesson website - and I'm trying to implement a musical code language VexTab. 

[vextab width=800]

tabstave notation=yes

[/vextab]

translates into

<div class="vex-tabdiv" width=800>

tabstave notation=yes

</div>

and there is more functionality, I will not bore you with this. 

My problem: when I use an hashtag (#) in this code, MarkupShortcodes won't recognize the [vextab]#[/vextab] as a shortcode. Same appears to be happening with &. I tried to translate the # into the html equivalent - but this doesn't help because this contains an hashtag as wel...

With my limited knowledge of PHP I tried to work it out myself but I haven't figured it out yet. Do you have an idea how to make your shortcode script compatible with some other symbols including #?

Thanks in advance!

Jesse

Link to comment
Share on other sites

  • 9 months later...

i understand this is a very old question...

Is it possible to get $page available inside the add function?

$shortcode->add('foo', function($atts){
    I WANT $page here!
});

if $page is available wherever you define the shortcode closure:

$shortcode->add('foo', function ($atts) use ($page) {
    //NOW I CAN USE $page here!
});

but of course, wire() makes all the pw api vars available to you.

  • Like 1
Link to comment
Share on other sites

SHORTCODE DEFINITIONS FILE INCLUSION:

Hello Niko,

i was thinking....

- we could define a standard or configurable location for the shortcode definition file.

- we could add an initialized property for the module

- when $shortcode->initialized == false we force the shortcode load the definition file and set $shortcode->initialized = true

. we check for initialized inside the render method, if not => load the file

so if we don't need shortcode rendering in a page render we avoid loading the definition file

use case (let's assume we wants to parse the body field)

if ($body = $page->body) {
    echo $shortcode->render($body);
}

if !$body => the definition file would not be loaded.

what do you think?

(in silverstripe 3.1 i ported the wp shortcode parser and the callbacks definition were actually static methods in a static class)

kind regards

Link to comment
Share on other sites

Hello Niko,

i quiclky ported the wp shortcodes parser i made for SIlverstripe 3.1 to this:

https://github.com/pine3ree/MarkupWPShortcodes

of course being a port of the same library it's quite similar to yours.

The module loads a default (*) definition file if found. You have also a public load($fullPath) to load other files other then default in templates. Or you can just use the add method. (*)I am in a hurry for a project so i didn't make it configurable, but that's easy to add.

Inside the definition files, since are included inside the class you add shortcodes like this:

$this->add('test1', function ($atts) {
    echo '<h3>This is a test shortcode with tag=test1</h3>';
});

in a template you can call:

$shortcodes->load($config->paths->templates .'/shortcodes/extra.inc');

to add custom definitions for that template

or simply, like your module:

$shortcodes->add('test2', function ($atts) {
    echo '<h3>This is a test shortcode with tag=test2</h3>';
});

let me know if you have other suggestions to make it better,

kind regards

Link to comment
Share on other sites

  • 2 weeks later...

Hey,

sorry for late answer but I were on vacation the last days.

Looks really nice what you have done. I had neither time for trying it nor compare it with my module but I definitely will do this within the next week.

Thanks!

-- Nico

Link to comment
Share on other sites

Thank You,

hope you enjoied your vacation. :-)

It was a real quick port I needed up and running. I'm sure that you - not being new at pw as am I - will be able to port the idea in a better and more elegant way into your more known and tested module.

kindly

  • Like 1
Link to comment
Share on other sites

  • 8 years later...

hello,

my provides has updated to php 8.0 – now i am facing problems mainly with MarkupShortcodes. it does not work.

any ideas?

sos!

oli

ps debug info: 

What the… Fatal Error: Uncaught Error: Call to undefined function wire() in site/templates/contactform.inc:6

#0 site/templates/basic-page.php (35): include()
#1 site/modules/MarkupShortcodes.module (90): TemplateFile->{closure}(Array)
#2 [internal function]: MarkupShortcodes->{closure}(Array)
#3 site/modules/MarkupShortcodes.module (92): preg_replace_callback('%\\[kontakt]%s', Object(Closure), '<p>Sende uns ei...')
#4 site/templates/basic-page.php (40): MarkupShortcodes->render('<p>Sende uns ei...')
#5 wire/core/TemplateFile.php (327): require('/is/htdocs/wp13...')
#6 wire/core/Wire.php (414): TemplateFile->___render()
#7 wire/core/WireHooks.php (951): Wire->_callMethod('___render', Array)
#8 wire/core/Wire.php (485): WireHooks->runHooks(Object(TemplateFile), 'render', Array)
#9 wire/modules/PageRender.module (575): Wire->__call('render', Array)
#10 wire/core/Wire.php (417): PageRender->___renderPage(Object(HookEvent))
#11 wire/core/WireHooks.php (951): Wire->_callMethod('___renderPage', Array)
#12 wire/core/Wire.php (485): WireHooks->runHooks(Object(PageRender), 'renderPage', Array)
#13 wire/core/WireHooks.php (1059): Wire->__call('renderPage', Array)
#14 wire/core/Wire.php (485): WireHooks->runHooks(Object(Page), 'render', Array)
#15 wire/modules/Process/ProcessPageView.module (184): Wire->__call('render', Array)
#16 wire/modules/Process/ProcessPageView.module (114): ProcessPageView->renderPage(Object(Page), Object(PagesRequest))
#17 wire/core/Wire.php (417): ProcessPageView->___execute(true)
#18 wire/core/WireHooks.php (951): Wire->_callMethod('___execute', Array)
#19 wire/core/Wire.php (485): WireHooks->runHooks(Object(ProcessPageView), 'execute', Array)
#20 index.php (55): Wire->__call('execute', Array)
#21 {main}
thrown (line 6 of site/templates/contactform.inc)  

This error message was shown because: site is in debug mode. ($config->debug = true; => site/config.php). Error has been logged.

 

Link to comment
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
 Share

×
×
  • Create New...