Assemble - can't reuse {{>body}}: "The partial body could not be found" - gruntjs

First of all, forgive me if this is a silly question. I am new to assemble (started using it last week) and StackOverflow.
I'm trying to use the partial "body" twice on a layout, like this:
{{>body}}
{{>body}}
And I get the error message from the title: The partial body could not be found.
My original intention actually was to use that for selective markdown rendering, such as:
{{#is (extname page.src) "md"}}
{{#markdown}}
{{>body}}
{{/markdown}}
{{else}}
{{>body}}
{{/is}}
But in that case I get the same error when the page is not markdown.
Does this sound like a legit issue? Just trying to help, that's all. :-)
(BTW, for the selective markdown issue I just implemented a {{#markdown-if}} helper that does the job, so I don't need help getting that logic to work. I just want to help assemble in case this behavior I found sounds like a real issue.)

This is an interesting use case... We used to register the page content as a body partial, but stopped doing that and instead use Regex to replace the {{>body}} tag with the page content. I think you should open an issue to request that we substitute all the body tags instead of just the first occurrence.
So to answer the question... Assemble does a string.replace and only replaces the first occurrence, so you'll get an error if trying to use {{>body}} twice.

I was able to fix this in 0.4.12 with the initializeEngine option and changing the two {{> body }} references to just {{ body }}
See https://github.com/assemble/assemble/pull/468#issuecomment-38730532

Related

How to get current year in a Nunjucks template within Apostrophe CMS

I am in the process of adding a copyright line to the footer of a website that I have been working on and I cannot find the best way to get the current dynamically into the footer so I never have to set it again. I have tried multiple things, including a global setting that can be accessed from anywhere, but nothing has worked.
Any feedback would be appreciated. Thanks.
Write an ApostropheCMS nunjucks helper function. See those docs for the general issues around this. Your specific function could look like:
self.addHelpers({
thisYear: function() {
return new Date().getFullYear();
}
});
If you put that in construct of a module of your own, let's say it's called helpers, then you can call it in Nunjucks as {{ apos.helpers.thisYear() }}.
These are very handy, just remember they cannot do any async work.

Scrapy: Unable to access class despite of it's there

I am trying to scrape this page, I am trying to fetch Color Name, LT. BLUE. From Chrome I see HTML:
<div id="desc-options"><div class="option"><span class="label">Color:</span> LT. BLUE</div><div class="option"><span class="label">Size:</span> 6.5</div></div>
I tried response.css("#desc-options") to access everything inside but returns []. Even BeautifulSoup is failing.
The element you're looking for is dynamically created via JavaScript. You cannot parse it from the plain HTML.
The good news is: the data you're looking for is probably still in the page. Check out the <script> tag defining the spConfig variable. Looks like there's some JSON there you can parse ...

The Binding Only Updates After Clicking the Element, Though the String in the Controller Has Already Been Updated (Angular 1.5)

I have an ng-class attribute (that I didn't write on my own). It is bound to a string variable in the controller . It looks like: <some-tag ng-class="'indicator_' + $ctrl.stringValue"></some-tag>.
When the window first load - it contain the correct data, but after the string is updated in the controller - the value in the class attribute only updates after I'm clicking the element (the click will open a list, but I don't think it's relevant).
I've read that the first thing to check in these cases, is that the code is surrounded by a $scope.$apply. It is, cause when I try to add it - I get an error saying "$digest already in progress".
Looking for $ctrl and ng-class info, I read the AngularJS component doc and this site, that gave me some basic background about these subjects.
The thing is, I couldn't find any examples of ng-class with $ctrl. Maybe it's irrelevant, but maybe not :)
Example for an irrelevant question I found in the subject is: Angular ngClass is not updating my classes even though my condition change as expected.
In general, most of the examples I found include curly brackets, which I don't think are relevant in this case, since I'm binding a string (maybe I'm mistaking about it :) ).
I suspect it probably didn't bind it correctly, I just don't know why.
Edit:
After continuing to search the subject, I'm no longer sure it's related to the ng-class (so I edited the title as well). It looks more like a refresh problem.
I'm puzzled as to why the page doesn't refresh, since everywhere I read - they say that the Angular should call the digest function on its own, and I should not interfere.
Edit2:
I'm working with typeScript, and the stringValue is updated via an event from a service. But the string does update - so I'm not sure it is a relevant information to understand the problem, but worth mentioning :)
Problem solved!! :D
All I had to do, is to add $timeout(0) after updating the string in the controller!
The explanation: it was a digest problem, and the reason I couldn't use $scope.$apply(), is because I was trying to do it directly. I needed to do a safe apply, which means - first make sure there's no digest on that scope, and then run apply.
Turns out that an easy way to do it, is to use $timeout(0).
I prepared a plunker with Angular 1.5.7 with a demo of what you described. There doesn't seem to be any problem, or anything special you should do. (I used a different alias for the controller, which is the best practice, but $ctrl works fine as well.)
https://plnkr.co/edit/wCpBQ5?p=preview
const DemoComponent = {
controller: DemoController,
controllerAs: 'demoCtrl',
template: `
<h2 ng-class="'demo_' + demoCtrl.classSuffix">{{ demoCtrl.classSuffix }}</h2>
<button ng-click="demoCtrl.changeClass()">Change Class</button>
`
}
angular.module('myapp', [])
.component('demo', DemoComponent);
It will be very helpful if you can reproduce the issue in plunker and post the link.
Otherwise, I hope you find the answer in this plunker.

Parsing page data into sidebar - wordpress

What would be the proper procedure for accessing the current page html data and picking up all of a certain tag and throwing them into the sidebar as links?
I'm not sure your proficiency with php, but I'll give you and overview of what you'd probably want to do.
First, you need the HTML. I'm assuming you're running this on a page (in a page.php file or single.php file, or similar), this means that you have access to the global variable $post, which contains the html of the page in it. To access it you can use the helper function get_the_content(), this returns the html being displayed.
Next you need to parse through this to get the h2 tags. A simple regex can handle this, something like <h2[^>]*>(.*)</h2>. It's important to remember that this regex is very picky, so format your html correctly, no multiline h2s.
So now you have the html, and have parsed it with a regex to get the h2s. Now you need to generate the list from the results, and prepend it to the top of the content of the page. There are a ton of ways to do this, the easiest being just running the code in the right spot in the template file.
Of course there are probably better ways of doing this, I'd recommend you look at say a FAQ plugin (if that's what this is for), or do the lists manually (as this system can be broken), or possibly use a custom post type; but for your question, that's how I'd do it.

How to create a bookmarklet for creating a screen scraping?

How to create a bookmarklet like this one: http://www.vimeo.com/1626505
I want to create one the same, where to start? i want to know the work flow of how this one is working to build my own.
Thanks
A bookmarklet is just a javascript program written on a single line of code replacing the usual location attribute (http://www.somestuffhere.com) on a bookmark.
To build your own bookmarklet, I suggest you to use Firebug :
- type your code inside firebug and execute it until what you want to do is working,
- then, remove all new lines in order to have a big one line piece of code,
- create a new bookmark in your browser and, in the location field, write javascript: and copy-paste your single line of code.
You can try a simple bookmarklet by typing that directly in your browser location bar : javascript: alert('this is a very simple bookmarklet'); then type enter to execute it.
Here is a handy bookmarket builder I have sometimes used. It can squash many lines of javascript into one line that can be set as the 'target' of a bookmark
(there may very well be better ones out there than this, but its done the job well for me)

Resources