{"action":"created","issue":{"url":"https://api.github.com/repos/timber/timber/issues/1654","repository_url":"https://api.github.com/repos/timber/timber","labels_url":"https://api.github.com/repos/timber/timber/issues/1654/labels{/name}","comments_url":"https://api.github.com/repos/timber/timber/issues/1654/comments","events_url":"https://api.github.com/repos/timber/timber/issues/1654/events","html_url":"https://github.com/timber/timber/issues/1654","id":294755300,"number":1654,"title":"[bug] - Timber (or Twig?) generates duplicate entries for \"function wp_nonce_field\"","user":{"login":"7php","id":7369626,"avatar_url":"https://avatars3.githubusercontent.com/u/7369626?v=4","gravatar_id":"","url":"https://api.github.com/users/7php","html_url":"https://github.com/7php","followers_url":"https://api.github.com/users/7php/followers","following_url":"https://api.github.com/users/7php/following{/other_user}","gists_url":"https://api.github.com/users/7php/gists{/gist_id}","starred_url":"https://api.github.com/users/7php/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/7php/subscriptions","organizations_url":"https://api.github.com/users/7php/orgs","repos_url":"https://api.github.com/users/7php/repos","events_url":"https://api.github.com/users/7php/events{/privacy}","received_events_url":"https://api.github.com/users/7php/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-02-06T13:16:15Z","updated_at":"2018-02-06T14:31:59Z","closed_at":null,"author_association":"NONE","body":"Is this a support or usage question? Please post to [StackOverflow]\r\n- **Support**\r\n### Expected behavior\r\nShould generate the following:\r\n```\r\n<div>\r\n    <input type=\"hidden\" id=\"name_wpnonce\" name=\"name_wpnonce\" value=\"a81d292134\" />\r\n    <input type=\"hidden\" name=\"_wp_http_referer\" value=\"/product-category/custompage/\" />\r\n</div>\r\n```\r\n### Actual behavior\r\nBut the following duplicate entries are being generated:\r\n\r\n```\r\n<div>\r\n    <input type=\"hidden\" id=\"name_wpnonce\" name=\"name_wpnonce\" value=\"a81d292134\" />\r\n    <input type=\"hidden\" name=\"_wp_http_referer\" value=\"/product-category/custompage/\" />\r\n    <input type=\"hidden\" id=\"name_wpnonce\" name=\"name_wpnonce\" value=\"a81d292134\" />\r\n    <input type=\"hidden\" name=\"_wp_http_referer\" value=\"/product-category/custompage/\" />\r\n</div>\r\n```\r\n\r\n### Steps to reproduce behavior\r\n- Create a simple twig file as follows:\r\n**custompage.twig**\r\n```\r\n<div>\r\n{{ function('wp_nonce_field', 'action_wpnonce', 'name_wpnonce') }}\r\n</div>\r\n```\r\n- In PHP code call:\r\n\r\n```\r\n$timber = \\Timber\\Timber::get_context();\r\n\\Timber\\Timber::render('twig/custompage.twig', $timber);\r\n```\r\n\r\n\r\n### What version of WordPress, PHP and Timber are you using?\r\n- WordPress 4.9.3\r\n- PHP 7.0.x\r\n- Timber 1.6.0\r\n\r\n### How did you install Timber? (for example, from GitHub, Composer/Packagist, WP.org?)\r\n- Via composer install\r\n"},"comment":{"url":"https://api.github.com/repos/timber/timber/issues/comments/363439423","html_url":"https://github.com/timber/timber/issues/1654#issuecomment-363439423","issue_url":"https://api.github.com/repos/timber/timber/issues/1654","id":363439423,"user":{"login":"7php","id":7369626,"avatar_url":"https://avatars3.githubusercontent.com/u/7369626?v=4","gravatar_id":"","url":"https://api.github.com/users/7php","html_url":"https://github.com/7php","followers_url":"https://api.github.com/users/7php/followers","following_url":"https://api.github.com/users/7php/following{/other_user}","gists_url":"https://api.github.com/users/7php/gists{/gist_id}","starred_url":"https://api.github.com/users/7php/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/7php/subscriptions","organizations_url":"https://api.github.com/users/7php/orgs","repos_url":"https://api.github.com/users/7php/repos","events_url":"https://api.github.com/users/7php/events{/privacy}","received_events_url":"https://api.github.com/users/7php/received_events","type":"User","site_admin":false},"created_at":"2018-02-06T14:31:59Z","updated_at":"2018-02-06T14:31:59Z","author_association":"NONE","body":"@gchtr thank you very much for being so quick & responsive, you are awesome.\r\n\r\nThank you for the very nice explanation and it makes sense.\r\nIn addition to the two solutions you mention, I am using this one below:\r\n\r\n1) In TWIG file, do:\r\n```\r\n<div>\r\n{{ _wpnounce_ }}\r\n</div>\r\n```\r\n\r\n2) In PHP code, do the method call there:\r\n```\r\n$timber = \\Timber\\Timber::get_context();\r\n$timber = [\r\n    '_wpnounce_'  => wp_nonce_field('action_wpnonce', 'name_wpnonce')\r\n];\r\n\\Timber\\Timber::render('twig/custompage.twig', $timber);\r\n```\r\n\r\nOnce again thank you very as the `{% do … %}` is very good to know so that I can use it in other methods or even this one.\r\n\r\nHave a good remaining day.\r\n\r\nHumbly,\r\n7php\r\n(Khayrattee)"}}
{"actor":{"display_login":"7php"}}