{"action":"created","issue":{"url":"https://api.github.com/repos/textpattern/textpattern.github.io/issues/112","repository_url":"https://api.github.com/repos/textpattern/textpattern.github.io","labels_url":"https://api.github.com/repos/textpattern/textpattern.github.io/issues/112/labels{/name}","comments_url":"https://api.github.com/repos/textpattern/textpattern.github.io/issues/112/comments","events_url":"https://api.github.com/repos/textpattern/textpattern.github.io/issues/112/events","html_url":"https://github.com/textpattern/textpattern.github.io/issues/112","id":377462271,"node_id":"MDU6SXNzdWUzNzc0NjIyNzE=","number":112,"title":"variable and if_variable tag clarifications","user":{"login":"wion","id":948658,"node_id":"MDQ6VXNlcjk0ODY1OA==","avatar_url":"https://avatars0.githubusercontent.com/u/948658?v=4","gravatar_id":"","url":"https://api.github.com/users/wion","html_url":"https://github.com/wion","followers_url":"https://api.github.com/users/wion/followers","following_url":"https://api.github.com/users/wion/following{/other_user}","gists_url":"https://api.github.com/users/wion/gists{/gist_id}","starred_url":"https://api.github.com/users/wion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wion/subscriptions","organizations_url":"https://api.github.com/users/wion/orgs","repos_url":"https://api.github.com/users/wion/repos","events_url":"https://api.github.com/users/wion/events{/privacy}","received_events_url":"https://api.github.com/users/wion/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":16,"created_at":"2018-11-05T15:54:11Z","updated_at":"2018-11-06T18:31:22Z","closed_at":null,"author_association":"MEMBER","body":"I can't remember if I ever really knew how to use variables, or I just forgot, but I find them a little confusing now and the docs don't help at all. Maybe I'll try to improve the `variable` and `if_variable` docs, but first I have to understand them. The usual game. So following is what I understand, or think I understand, and what I  don't understand at all. Please someone put me right.\r\n\r\n## `variable`\r\n\r\nCan be used as a container or single tag.\r\n\r\nIt has two attributes: `name=\"\"` and `attribute=\"\"`.\r\n\r\nThe `name` attribute seems straightforward enough. In order to use a variable at all (let alone assign a value to it), it must have a name.\r\n\r\nSo let's say we want a variable named 'string', and we want to assign a value to that variable equaling 'This is my string'. To do this as a container tag, it would be:\r\n\r\n```\r\n<txp:varible name=\"string\">\r\nThis is my string.\r\n</txp:variable>\r\n```\r\n\r\nHow would we use that variable now?  I don't know.\r\n\r\nDo assign the same value as a single tag:\r\n\r\n```\r\n<txp:varible name=\"string\" value=\"This is my string.\" />\r\n```\r\n\r\nAgain, how would we use that? I don't know.\r\n\r\nBut I do know that some version of the variable must be put _above_ where the value needs to be output. Example one in the [variable](https://docs.textpattern.com/tags/variable#examples) doc seems to try to explain that idea, but not very well. The example seems like a lot of needless code and doesn't elucidate why the sole instance of the variable tag is at the bottom of it. Beats me.\r\n\r\nAnd apparently you can also do this?\r\n\r\n* `<txp:variable name='string' value=\"\" />`\r\n* `<txp:variable name='string' value=\"0\" />`\r\n* `<txp:variable name='string' value=\"1\" />`\r\n\r\nBut I have no clue what those mean exactly, or why you would use one over the other, and the aforementioned doc doesn't mention any of them in the attributes section, nor any examples given.\r\n\r\nSo, you can see where some deficiencies are for the those like me who need the detail.\r\n\r\n## `if_variable`\r\n\r\nJumping ahead to the `if_variable` tag. Presumably once you have a global variable set to one's liking, you can then call the assigned value in a conditional way, if needed:\r\n\r\n```\r\n<txp:if_variable name=\"string\">\r\n  <em><txp:variable name=\"string\" />.</em> It's doing its thing.\r\n</txp:if_varible>\r\n```\r\nWhich could also be written using the new tag structure syntax, as:\r\n\r\n```\r\n<if::variable name=\"string\">\r\n  <em><txp:variable name=\"string\" /></em> It's doing its thing.\r\n</if::varible>\r\n```\r\n\r\nEither way, it would output as:\r\n\r\n'_This is my string._ It's doing its thing.'\r\n\r\nIf someone will help me iron out the kinks in all this, I will commit to augmenting the docs with what I learn. Other pea brains like me should appreciate it.\r\n "},"comment":{"url":"https://api.github.com/repos/textpattern/textpattern.github.io/issues/comments/436358791","html_url":"https://github.com/textpattern/textpattern.github.io/issues/112#issuecomment-436358791","issue_url":"https://api.github.com/repos/textpattern/textpattern.github.io/issues/112","id":436358791,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNjM1ODc5MQ==","user":{"login":"Bloke","id":21252,"node_id":"MDQ6VXNlcjIxMjUy","avatar_url":"https://avatars0.githubusercontent.com/u/21252?v=4","gravatar_id":"","url":"https://api.github.com/users/Bloke","html_url":"https://github.com/Bloke","followers_url":"https://api.github.com/users/Bloke/followers","following_url":"https://api.github.com/users/Bloke/following{/other_user}","gists_url":"https://api.github.com/users/Bloke/gists{/gist_id}","starred_url":"https://api.github.com/users/Bloke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bloke/subscriptions","organizations_url":"https://api.github.com/users/Bloke/orgs","repos_url":"https://api.github.com/users/Bloke/repos","events_url":"https://api.github.com/users/Bloke/events{/privacy}","received_events_url":"https://api.github.com/users/Bloke/received_events","type":"User","site_admin":false},"created_at":"2018-11-06T18:31:22Z","updated_at":"2018-11-06T18:31:22Z","author_association":"MEMBER","body":"> So you're saying value=\"0\" and value=\"\" are equivalent?\r\n\r\nIn Txp, no. You can test for '0' distinct from 'empty'. This helps if you want to distinguish a counter that hasn't been initialised vs one that had started to be used but hasn't yet been incremented.\r\n\r\nWith regards a variable tag with no value, yes. That will output the current value assigned to the variable, whatever it may be. Could be a 1, a string, an entire set of articles, anything.\r\n\r\nIn the case you cite, that tag will output the current issue number read from the current context (URL or article, depending on what you're reading)."}}
{"actor":{"display_login":"Bloke"}}