-
Posts
408 -
Joined
-
Last visited
-
Days Won
4
Everything posted by WireCodex
-
This was tested and works... _func.php function toc( $heading, $content ) { $heading = str_replace( ',', ' ', $heading ); $heading = explode( ' ', $heading ); foreach ( $heading as $k => $v )$heading[ $k ] = trim( $v ); $heading = implode( '|', $heading ); $anchors = array(); if ( preg_match_all( '{<(' . $heading . ')[^>]*>(.+?)</\1>}i', $content, $matches ) ) { foreach ( $matches[ 1 ] as $key => $tag ) { $text = $matches[ 2 ][ $key ]; $anchor = wire('sanitizer')->pageName($text, true); $anchors[ $anchor ] = $text; $full = $matches[ 0 ][ $key ]; $content = str_replace( $full, "<a name='$anchor' href='#'></a>$full", $content ); } } if ( count( $anchors ) ) { $toc = "<ul class='article-toc'>"; $url= wire('page')->url; foreach ( $anchors as $anchor => $text ) { $toc .= "<li><a href='$url#$anchor'>$text</a></li>"; } $toc .= "</ul>"; return array( $toc, $content ); } else { return null; } } article.php (example template file) <?php $out = toc("h2 h3 h4",$page->body); ?> <div class="page"> <div class="main"> <?=$out[1]?> </div> <div class="sidebar"> <h3>Table of Contents</h3> <?=$out[0]?> </div> </div> the previous published function was updated because we need to use wire() in _func.php
- 14 replies
-
- 1
-
-
- table of content
- anchor
-
(and 1 more)
Tagged with:
-
ProcessWire Core & jQuery Future !
WireCodex replied to Mustafa-Online's topic in Wishlist & Roadmap
my comment was ironic about avoid 3rd party dependencies -
ProcessWire Core & jQuery Future !
WireCodex replied to Mustafa-Online's topic in Wishlist & Roadmap
I'm in the web design since 1998, and I remember when the war against inline styles began, you put a little style="margin-bottom:10px" in a unique element in the project and you are a renegade man from the old days, you need to create a new css class for it ... after decades learning to avoid them at all cost.. now in 2017 the new trend that coder influencers propose as good modern practices (because of React, etc) is using it! you get this and is OK.. Whaaat? !! ..hahaha.. the previous was a joke.. but seriously.. the best practice is to be practical, logic and simple always as @BitPoet said -
ProcessWire Core & jQuery Future !
WireCodex replied to Mustafa-Online's topic in Wishlist & Roadmap
For me, the reality is that when I use "vanilla" scripts, each one coming from different developers with its own code for dom traversal and manipulation, yes they are in plain js without dependencies ... but with a tons of redundant code for the same tasks ... so when I finally managed to finish a complex website with sliders, accordions, calendar, date selectors, drop-down menus, parallax, forms and looong, etc. each has its own code to select nodes, add/remove classes and looong, etc. I have a lot of repetitive code, for what? For a trend? yes it's true jQuery 1x is obsolete and fat due to the support of old browsers, but jQuery 3x is as slim as you need. The reality is that we need a library for common tasks (give it the name you want). For today jQuery allows me to do simple tasks on a regular website without additional efforts (ie a website like processwire.com, not a web application, or a project for Córdoba).. well.. if someone create that library, pleeeease use an API similar to PW/JQUERY.. it's so easy to use and learn for us, the non pro developers!!- 32 replies
-
- 18
-
-
ProcessWire Core & jQuery Future !
WireCodex replied to Mustafa-Online's topic in Wishlist & Roadmap
So, we should build the next PW admin without uikit framework too? Because we will no longer depend on jQuery but will depend on UIKit or any other library that we need to function properly. Really I don't understand which is the trending goal of eliminating jQuery like a disease? -
You can adapt the following Hanna Code example to a function for output anywhere... without dependencies ---------------- Jumplinks Hanna Code This Hanna code is meant to be used in your body copy. It collects all the headline tags in the text and turns them into anchor jump links while outputting a linked table of contents. It will put the table of contents wherever you type the Hanna code. $for = str_replace(',', ' ', $for); $for = explode(' ', $for); foreach($for as $k => $v) $for[$k] = trim($v); $for = implode('|', $for); $anchors = array(); $value = $hanna->value; if(preg_match_all('{<(' . $for . ')[^>]*>(.+?)</\1>}i', $value, $matches)) { foreach($matches[1] as $key => $tag) { $text = $matches[2][$key]; $anchor = $sanitizer->pageName($text, true); $anchors[$anchor] = $text; $full = $matches[0][$key]; $value = str_replace($full, "<a name='$anchor' href='#'></a>$full", $value); } $hanna->value = $value; } if(isset($topic)) { $topic = $topic; } else { $topic = 'Page'; } if(count($anchors)) { echo "<div class='toc'>"; echo "<p>On this $topic:</p>"; echo "<ol class='article-toc'>"; foreach($anchors as $anchor => $text) { echo "<li><a href='$page->url#$anchor'>$text</a></li>"; } echo "</ol>"; echo "</div>"; } else { echo ''; } Usage Examples: [[jumplinks]] Locates all h2 and h3 headlines, turns them into anchors, and generates a table of contents. This is the default behavior with no attributes. [[jumplinks for=h2]] Here we specify a 'for' attribute. It produces the same behavior as above except only anchors h2 headlines. [[jumplinks for="h2 h4"]] Same as above except only anchors h2 and h4 headlines. ---------------- $for is the heading tags that you want to link in the TOC $hanna->value is the string with the html content you want to process and update This script modify the original HTML content to include the new anchors, and create the markup for the TOC. Instead of direct echo the markup, you need to return the output... maybe something like the following code (you need to check if I'm using the PHP best practices because I'm not a coder) function toc( $heading, $content ) { $heading = str_replace( ',', ' ', $heading ); $heading = explode( ' ', $heading ); foreach ( $heading as $k => $v )$heading[ $k ] = trim( $v ); $heading = implode( '|', $heading ); $anchors = array(); if ( preg_match_all( '{<(' . $heading . ')[^>]*>(.+?)</\1>}i', $content, $matches ) ) { foreach ( $matches[ 1 ] as $key => $tag ) { $text = $matches[ 2 ][ $key ]; $anchor = $sanitizer->pageName( $text, true ); $anchors[ $anchor ] = $text; $full = $matches[ 0 ][ $key ]; $content = str_replace( $full, "<a name='$anchor' href='#'></a>$full", $content ); } } if ( count( $anchors ) ) { $toc = "<ul class='article-toc'>"; foreach ( $anchors as $anchor => $text ) { $toc .= "<li><a href='$page->url#$anchor'>$text</a></li>"; } $toc .= "</ul>"; return array( $toc, $content ); } else { return null; } } ..or maybe output only the $anchors array and customize the markup in your template according to your page design
- 14 replies
-
- 7
-
-
- table of content
- anchor
-
(and 1 more)
Tagged with:
-
Good point about usability, maybe something like a outlined button could work. I would not like to replace the current link with a dropdown menu because it would be better to preserve the function of the current link and add the new function. The theme is the regular Reno that comes with PW installation, you can access it in the admin profile.
-
yes, off course you are right about the ids.. I only change the div for the pw-region tags
-
Don't use div element in the document head, it's incorrect.. instead use this Processwire markup region option <pw-region id="title-region"> <title id="title-region"><?php echo $page->title; ?> | <?php echo $page->template->name; ?> | schildpad | Chrysemys</title> </pw-region> ... <pw-region id="google_map"></pw-region>
-
Hi guys! What do you think about something like this? Because I use this option regularly in the Windows File Explorer breadcrumb and it's very useful. The drop-down menu can display only published/visible child pages. I've tried to find how to do it as a module, but I'm not a coder with enough skills for that ... or I don't know if I can use hooks to do that ...
- 13 replies
-
- 13
-
-
check this too: https://www.fastcomet.com/ (https://www.fastcomet.com/processwire-hosting)
-
I think you can do this with your own function with a str_replace inside and passing the field string and the values array like in this post from @Macrura https://processwire.com/talk/topic/12969-intermediate-template-structure-without-string-concatenation/?do=findComment&comment=117616 in your case the variable $tpl is filled with the content of your field instead of file_get_contents
-
Markup Regions - add class without replacing content
WireCodex replied to adrian's topic in API & Templates
As I understand based on documentation should do the same <div id="foo" pw-prepend> = <div pw-prepend="foo"> -
Markup Regions - add class without replacing content
WireCodex replied to adrian's topic in API & Templates
https://processwire.com/blog/posts/processwire-3.0.62-and-more-on-markup-regions/#actions-for-populating-regions -
Markup Regions - add class without replacing content
WireCodex replied to adrian's topic in API & Templates
you can try this: <body pw-append='html-body' class='bgimage'></body> and leave empty the DIV maybe should add only the class -
I try it but in the Field setting page I get this error: ProcessField: Method Page::getForPage does not exist or is not callable in this context and in the Page edit i get this: InputfieldRepeaterMatrix: Repeater 'layouts_main' preload 'page_list': Method Page::getForPage does not exist or is not callable in this context
-
I have a Page Reference Field and I need to select only the children pages of the current page where the field is edited. But the problem here is that the field is inside a Repeater, and the repeaters are actually another pages in the tree.. so where I can do easily using a custom code in ready.php like this: $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == 'page_list') { $event->return = $event->arguments('page')->children; } }); this don't work If the field is inside a Repeater.. I need to get the related page to the current repeater page to get the children, but how to do it?
-
..or if you want realtime search results, maybe you can try this: https://www.algolia.com/product ( I'm not an affiliate or promo agent )
-
I always use the Markup Region since it was included in PW .. thanks for your advice, thanks for everything guys, this community is really like a home with friends
-
I agree with bernhard that this situation is perfect for an ajax solution, but in the parent page I use a javascript plugin that need the markup from the child pages is present in the html output at document ready, not in the dom
-
abdus: This don't works, if we generated the url segment links with: "./$page->name" we never found that page with: $codeChildName = "code--{$input->urlSegment1}" $pages("name=$codeChildName") because the page with that name doesn't exist but looking at your proposal I found one solution: add a "keyword" to the generated links and then remove that "keyword" after get that url segment.. works perfect! this at the start of my template file: <?php namespace ProcessWire; $wildcard = "-list"; if($input->urlSegment2) throw new Wire404Exception(); if($input->urlSegment1) { $request = $input->urlSegment1; } if($request) { $name = str_replace($wildcard,"",$request); $name = $sanitizer->pageName($name); $codes_page = $pages->get("name=$name"); if(!$codes_page->id) throw new Wire404Exception(); } else { $codes_page = $page->child("include=all"); } ?> then when I generated the links in the template: <?php foreach($page->children("include=all") as $child) { ?> <a href="<?=$child->name.$wildcard?>"><?=$child->title?></a> <?php } ?> and that's all.. it's ok? remember that I'm a graphic designer trying to coding
-
Abdus: the problem is that in the parent page I generate the links automatic from the name of the child pages, so the links always match the children names.. even if I add "code--" using the API because when I save the page, and later generate the parent page again the links will include "code--".. the only solution is to use a field other than the name ... ID is the best option because is url friendly.. Abdus: Thanks for your contributions to this forum, you are the best teacher for newbies like me, every post of yours seems a tutorial. It's easier to learn new things in them than with the PW documentation.
-
... Ooooh. I forgot it.. I'm in Florida (Waiting for the big hurricane uff) ... but is ok, maybe I don't have other solution than the IDs.. and I don't want to my editors to put the information in another place on the page tree when they should be under codes node... So, the last shoot.. the scenario is: Codes (template file) -- Wall Mount (template without file) -- Light Commercial (same as above) Initially Codes render its content (header, body, etc) plus the information of the first child (repeaters with body, pictures, etc) Codes also have a list of links that was generated from its children name as url segments, to load the same Codes page, but with the content from the new selected child .. uff seems more easier to see than to explain ! EDIT: this post should be before the previous from abdus, I delay in publishing it