Discussion:
[FreeMarker-user] dealing with page numbers
khrypt
2012-12-13 12:56:44 UTC
Permalink
Hi guys,
I'm a new user of FM and I need some help from you.
I'm working with some documents and encountered an issue I could not manage
yet..
So, int this documents there are some informations that may or may not
appear. If they do appear I have to know the number of that page. Here is
the issue.
By declaring a variable called pageNumber like:
[#assign pageNumber = "<s p a n id="pagenumber"/>" /] I can get the number
of the page.
But next, I need to remember this number. So I declare another variable
controlPage like:
[#assign controlPage = pageNumber /]... And here is the issue... This
*controlPage* will always evaluate as *<s p a n id="pagenumber"/>* but I
need to be just the value at that point/position where I've done the
assignment. Because if I'm printing the *controlPage* in all pages it will
have the value of current page (ex. 2, 3, 4, 5...) even if my declaration
was made somewhere on first page and I expect (1, 1, 1, 1, ...).

Thank you for your time.




--
View this message in context: http://freemarker.624813.n4.nabble.com/dealing-with-page-numbers-tp4654414.html
Sent from the freemarker-user mailing list archive at Nabble.com.
Denis Bredelet
2012-12-13 17:17:57 UTC
Permalink
Hi,
Post by khrypt
Hi guys,
I'm a new user of FM and I need some help from you.
I'm working with some documents and encountered an issue I could not manage
yet..
So, int this documents there are some informations that may or may not
appear. If they do appear I have to know the number of that page. Here is
the issue.
[#assign pageNumber = "<s p a n id="pagenumber"/>" /] I can get the number
Are you sure you are using double-quotes this way? I am not even sure what this is supposed to do.
Post by khrypt
of the page.
But next, I need to remember this number. So I declare another variable
[#assign controlPage = pageNumber /]... And here is the issue... This
*controlPage* will always evaluate as *<s p a n id="pagenumber"/>* but I
need to be just the value at that point/position where I've done the
assignment. Because if I'm printing the *controlPage* in all pages it will
have the value of current page (ex. 2, 3, 4, 5...) even if my declaration
was made somewhere on first page and I expect (1, 1, 1, 1, ...).
Thank you for your time.
Daniel Dekany
2012-12-13 19:11:43 UTC
Permalink
Post by khrypt
Hi guys,
I'm a new user of FM and I need some help from you.
I'm working with some documents and encountered an issue I could not manage
yet..
So, int this documents there are some informations that may or may not
appear. If they do appear I have to know the number of that page. Here is
the issue.
[#assign pageNumber = "<s p a n id="pagenumber"/>" /] I can get the number
of the page.
What do mean by you can get it? How? You have just assigned a constant
string to `pageNumber`. (Barring the syntactical error; I assume it
was `[#assign pageNumber = '<span id="pagenumber" />' /]`.) It means
nothing for FreeMarker, it's just an arbitrary sequence of characters
for it.
Post by khrypt
But next, I need to remember this number. So I declare another variable
[#assign controlPage = pageNumber /]
So now `controlPage` holds the same string constant. I guess you
expect something else to happen, but what exactly and why?
Post by khrypt
... And here is the issue... This *controlPage* will always evaluate
as *<s p a n id="pagenumber"/>*
Since it's just a constant, yes.
Post by khrypt
but I need to be just the value at that point/position where I've
done the assignment.
The value of what at the point assignment? The current page number?
What keeps track of the current page number? Or if nothing yet, what
separates the pages? Because at those points you could increase a page
counter variable.
Post by khrypt
Because if I'm printing the *controlPage* in all pages it will
have the value of current page (ex. 2, 3, 4, 5...) even if my declaration
was made somewhere on first page and I expect (1, 1, 1, 1, ...).
Um... the whole thing is rather strange. What are those spans, and why
are they relevant? How do you expect them to count the pages, if you
do at all?
Post by khrypt
Thank you for your time.
--
Best regards,
Daniel Dekany
khrypt
2012-12-14 09:15:23 UTC
Permalink
Hi Daniel, thank you for you attention.
First:
/"What do mean by you can get it? How? You have just assigned a constant
string to `pageNumber`. (Barring the syntactical error; I assume it
was `[#assign pageNumber = '<spa n id="pagenumber" />' /]`.) It means
nothing for FreeMarker, it's just an arbitrary sequence of characters
for it."/
-- the syntactical error I've made-it intentionally here.. yes, this is the
correct declaration.

Second:
/"So now `controlPage` holds the same string constant. I guess you
expect something else to happen, but what exactly and why?"/
-- well, here I was expecting to get the value of that instruction.. This
span is a css instruction defined as:
#pagenumber:before {content: counter(page);} and in the final step of
processing the document it will give me the number of current page.

Third:
/"The value of what at the point assignment? The current page number?
What keeps track of the current page number?* Or if nothing yet*, what
separates the pages? Because at those points you could increase a page
counter variable."/
-- here you have a point, probably if no for certain at the "freemarker
step" my variables are just some strings, and only in the last step "to pdf"
this strings will be evaluated as css directives. Didn't thought about it
until now. And this mean that I'm screwed....
Fourth:
"Um... the whole thing is rather strange. What are those spans, and why
are they relevant? How do you expect them to count the pages, if you
do at all? "
-- Yes, this are css directives for counting pages. They are perfectly
working. Because of my lack of knowledge I've tried to combine css and
freemarker... Didn't work out. That's it. Thank you again for your time.



--
View this message in context: http://freemarker.624813.n4.nabble.com/dealing-with-page-numbers-tp4654414p4654417.html
Sent from the freemarker-user mailing list archive at Nabble.com.
Continue reading on narkive:
Loading...